我是編程新手。我想發送一封電子郵件給用戶,他們無法查看我的原始地址,這在收到的郵件中是可見的。如何使用c#從接收器中隱藏電子郵件地址?
這是我的代碼。請指導我必須做些什麼才能做到這一點。
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtUsername.Text, "Rajesh", System.Text.Encoding.UTF8);
// Recipient e-mail address.
Msg.To.Add(txtTo.Text);
Msg.ReplyTo =new MailAddress("[email protected]");
//Msg.ReplyTo = ("[email protected]");
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
Msg.SubjectEncoding = System.Text.Encoding.UTF8;
//txtUsername.Text,
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
Msg = null;
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Mail sent successfully!.Thank god.');if(alert){ window.location='default.aspx';}", true);
//ScriptManager.RegisterStartupScript();
//ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
//Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');window.close();</script>");
//if(alert){ window.location='SendMail.aspx';}
//}
//Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='default.aspx';}</script>");
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
請指導我實現目標的正確方法。
打開一個單獨的帳戶僅用於發送這些消息? – David
所以你跑這個?會發生什麼? –
它正確發送消息,接收方收到來自「[email protected]」的消息,顯示名稱爲「Rajesh」,並按照編碼發送給「[email protected]」。但我的要求是將「[email protected]」隱藏到接收方或替換電子郵件地址。 –