我在 C# 中制作了 asp.net webservice,以给定的 mailid 作为参数发送邮件。
邮件已发送,但显示为垃圾邮件,而不是收件箱邮件。
我使用了以下代码;
.NET 代码:
public int SendMail(string mailto, string username, string password)
{
try
{
string mailFrom = "test@gmail.com";
string siteName = "www.XYZ.com";
MailAddress fromAddress = new MailAddress(mailFrom, siteName);
SmtpClient mailClient = new SmtpClient();
MailMessage message = new MailMessage();
message.From = fromAddress;
message.To.Add(mailto);
message.Subject = "Your User Name and Password";
message.IsBodyHtml = true;
mailClient.Host = "relay-hosting.secureserver.net";
mailClient.UseDefaultCredentials = false;
mailClient.EnableSsl = false;
string body = "<HTML><BODY><CENTER><H2>Your User Name :'" + username + "' </H2><BR/><H2>Your Password :'" + password + "' </H2></CENTER></BODY></HTML>";
message.Body = body;
mailClient.Send(message);
return 1;
}
catch (Exception ex)
{
return 0;
}
}
WEB.CONFIG 代码:
<system.net>
<mailSettings>
<smtp from="test@gmail.com">
<network host="relay-hosting.secureserver.net" />
</smtp>
</mailSettings>
</system.net>
可能是什么问题?
谢谢..