如何发送电子邮件而不去垃圾邮件

时间:2014-04-30 05:10:00

标签: c# asp.net email

        MailAddress mailFrom = new MailAddress("test@smtp.com");
        MailAddress mailTo = new MailAddress("tester@gmail.com");
        MailMessage mail2 = new MailMessage(mailFrom, mailTo);
        mail2.IsBodyHtml = true;
        SmtpClient client = new SmtpClient();
        client.Port = 25;
        client.Host = "xxx.xx.xx.xxx"; // smtp host ip
        mail2.Subject = "Testing.";
        mail2.Body = "Hello";
        mail2.SubjectEncoding = System.Text.Encoding.UTF8;
        mail2.BodyEncoding = System.Text.Encoding.UTF8;
        client.Send(mail2);

以上是我的功能,用于通过smtp发送电子邮件,但我意识到所有邮件都位于我的垃圾邮件文件夹(Gmail)中。无论如何可以解决它吗?

2 个答案:

答案 0 :(得分:2)

  1. IsBodyHTML标记为true,但您只提供text / html。您最低限度需要包含带文本的备用视图

    mail2.Body ="您好";

  2. 确保您不使用Mail from和mailto是相同的地址或

    MailMessage mail2 = new MailMessage(mailFrom, mailTo);

  3. 更新

     mail2.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Port = 25;
            client.Host = "xxx.xx.xx.xxx"; // smtp host ip
            mail2.Subject = "Testing.";
            mail2.Body = "Hello";
            string html = "html";
            // here is example to user AlternateViews 
    
            mail2.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, new System.Net.Mime.ContentType("text/html"));
            string Plaintext ="plain text";
            mail2.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(Plaintext, new System.Net.Mime.ContentType("text/plain"));
            mail2.SubjectEncoding = System.Text.Encoding.UTF8;
            mail2.BodyEncoding = System.Text.Encoding.UTF8;
            client.Send(mail2);
    

答案 1 :(得分:0)

试试并恢复。

string mailServer;
int port;
string mailId, mailPass;
string subject;
string mailTo;
subject="something";
StringBuilder mailBody = new StringBuilder();
mailTo = "someone@gmail.com";
mailServer = "smtp.gmail.com";
mailId = "something@gmail.com";
myString.Length = 0;
myString.Append("<html><body><div>BODY CONTENT</div></body></html>");
mailPass = "xxxxxx";
port = 587;
MailMessage mail = new MailMessage(mailId, mailTo, subject, myString.ToString());
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(mailServer, port);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(mailId, mailPass);
smtp.UseDefaultCredentials = false;
smtp.Credentials = nc;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);