我的网站中有一个功能,它会向一个id发送一封电子邮件.Email包含一个指向网页和安全密钥的链接..但问题是它进入了垃圾文件夹
我使用Somee.com免费托管
代码:
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.Body = ("Copy The Link And paste It In Them follow Link <a href=\"http://localhost:52567/fu/Download.aspx\"> Download </a> </br>"+ encoded_url);
message.From = new MailAddress("lz-wag@hotmail.com");
message.To.Add(TextBox2.Text);
message.Subject = user + " Has Share The File With You";
try{
SmtpClient client = new SmtpClient();
client.Host = "smtp.live.com";
client.EnableSsl = true;
System.Net.NetworkCredential networkcred = new System.Net.NetworkCredential();
networkcred.UserName = "lz-wag@hotmail.com";
networkcred.Password = "password";
client.Port = 587;
client.Credentials = networkcred;
client.Send(message);
sendFile.Visible = false;
Label1.Visible = true;
Label1.Text = "Your File Has Been Shared";
}
catch(Exception ex){
Label1.Visible = true;
Label1.Text = "Your File Is Not Shared";
//Label1.Text = ex.ToString(); ;
}
答案 0 :(得分:2)
电子邮件是否进入垃圾邮件文件夹是电子邮件客户端的功能,而不是您发送电子邮件的功能。
但是,仅供参考,MailMessage
和SmtpClient
实施IDisposable
,因此应该在using
块中。像这样:
using (MailMessage message = new MailMessage())
{
// ...
using (SmtpClient client = new SmtpClient())
{
// ...
client.Send(message);
}
}
我还建议您在某处记录异常,否则在出现问题时您永远不会知道出了什么问题。