我正在使用mvc application 4.5。
我已经创建了邮件发送功能,邮件正文带有html表格并链接类似的东西,并附上pdf文件但每封垃圾邮件如何防止垃圾邮件
我的代码在
下面var message = new MailMessage();
message.From = from;
message.To.Add(to);
if (null != bcc)
{
foreach (var address in bcc.Where(bccValue => !String.IsNullOrWhiteSpace(bccValue)))
{
message.Bcc.Add(address.Trim());
}
}
if (null != cc)
{
foreach (var address in cc.Where(ccValue => !String.IsNullOrWhiteSpace(ccValue)))
{
message.CC.Add(address.Trim());
}
}
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = true;
using (var smtpClient = new SmtpClient())
{
smtpClient.UseDefaultCredentials = emailAccount.UseDefaultCredentials;
smtpClient.Host = emailAccount.Host;
smtpClient.Port = emailAccount.Port;
smtpClient.EnableSsl = emailAccount.EnableSsl;
if (emailAccount.UseDefaultCredentials)
smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
else
smtpClient.Credentials = new NetworkCredential(emailAccount.Username, emailAccount.Password);
string Gid = Guid.NewGuid().ToString();
string pdfcreateandpath = conversionsavepath + Gid + ".pdf";
bool flag = createpdf(contentconversion, conversionsavepath, pdfcreateandpath);
if (flag)
{
//
LogMessage(" pdf created is : " + flag);
if (System.IO.File.Exists(pdfcreateandpath))
{
LogMessage(" pdf file path exists is : " + System.IO.File.Exists(pdfcreateandpath));
// Attach pdf document here.
message.Attachments.Add(new Attachment(pdfcreateandpath));
smtpClient.Send(message);
}
答案 0 :(得分:1)
从代码发送的邮件可能因各种原因而转到垃圾邮件
阅读此页面http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/html/了解更多信息。
还尝试使用sendgrid http://sendgrid.com/transactional-email/pricing来测试您的代码,以确保您的服务器的IP不是黑名单。 Sendgrid为初学者提供免费计划。