SmtpClient sends email to junk

℡╲_俬逩灬. 提交于 2019-12-12 17:32:12

问题


I tried to send email from c# using SmtpClient.Send() but it always goes to the junk box. It works fine if I send it from Outlook. Is there anyway to solve this? Someone told me to modify the email header but I don't know how. Thanks in advance. Here is my code

SmtpClient client = new SmtpClient();
client.Host = "smtp.server.com";
client.Credentials = new System.Net.NetworkCredential("user", "password");
MailAddress mailFrom = new MailAddress("mymail@server.com");
MailAddress mailTo = new MailAddress("yourmail@server.com");
MailAddress mailReply = new MailAddress("mymail@server.com");
MailMessage message = new MailMessage(mailFrom, mailTo);
message.Body = "This is a test message.";
message.Subject = "test message";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
client.Send(message);

回答1:


a) The code sample doesn't actually use the mailReply address.

b) The problem will probably disappear when you send a more realistic message. If it doesn't then you will have to find out why the message is being marked junk, fishing a message from the spambox and looking at the headers or something like that.




回答2:


Spam filters may discard messages that have invalid entries.

Try putting in valid (existing) addresses of sender, reply and from.



来源:https://stackoverflow.com/questions/510748/smtpclient-sends-email-to-junk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!