如何发送电子邮件而不转到垃圾邮件 [英] how to send email without go to spam mail

查看:86
本文介绍了如何发送电子邮件而不转到垃圾邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        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)中。反正有什么可以解决的呢?

the above is my function that use to send an email via smtp, but I realized all the mail was located in my spam mail folder (Gmail). Is there anyway that can solve it ?

推荐答案


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

  1. IsBodyHTML is marked true, but you're only providing text/html. You minimally need to include an alternate view with text

mail2.Body = Hello;

mail2.Body = "Hello";

确保您使用的发件人和收件人不是相同的地址或

make sure you not using Mail from and mailto is same address or

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";
        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);

这篇关于如何发送电子邮件而不转到垃圾邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆