static string accountName = System.Configuration.ConfigurationManager.AppSettings["mailAccountName"];
static string password = System.Configuration.ConfigurationManager.AppSettings["mailPassword"];
static string smtpServer = System.Configuration.ConfigurationManager.AppSettings["mailSmtpServer"];
static int smtpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["mailSmtpPort"]);
static string displayName= System.Configuration.ConfigurationManager.AppSettings["mailDisplayName"];
static string userState= System.Configuration.ConfigurationManager.AppSettings["mailUserState"];
static public void SendMail(string sendTo, string subject, string body)
{
try
{
// Command line argument must the the SMTP host.
SmtpClient client = new SmtpClient(smtpServer, smtpPort);
client.UseDefaultCredentials = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential(accountName, password);
// Specify the e-mail sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress(accountName,
displayName,
System.Text.Encoding.UTF8);
// Set destinations for the e-mail message.
MailAddress to = new MailAddress(sendTo);
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = body;
// Include some non-ASCII characters in body and subject.
string someArrows = "(请勿回复这封邮件)";
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
client.Send(message);
message.Dispose();
client.Dispose();
}
catch { }
}
您好,
里边的:
new SmtpClient("smtpdm.aliyun.com", 25);
是否应该为:
new SmtpClient("smtp.dm.aliyun.com", 25);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。