SMTP验证错误"故障Sendng邮件" [英] SMTP Authentication Error "Failure Sendng Mail"
本文介绍了SMTP验证错误"故障Sendng邮件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,如果某些条件得到满足,从我的asp.net页面发送电子邮件。
I am trying to send email from my asp.net web page if certain conditions are fulfilled.
下面是我的code。
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential =
new NetworkCredential("username", "password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("from@yourdomain.com");
smtpClient.Host = "mail.mydomain.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add("to@anydomain.com");
try
{
smtpClient.Send(message);
}
catch(Exception ex)
{
//Error, could not send the message
Response.Write(ex.Message);
}
我没有共享服务器的详细信息。我想从我的Outlook电子邮件地址发送。不过,我不断收到一个错误: 发送邮件失败的
I have not shared the server details. I'm trying to send it from my outlook email address. However, I keep getting an error: Failure sending mail.
推荐答案
试试这个code
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);
smtpClient.Credentials = new System.Net.NetworkCredential("youremailid@gmail.com", "yourPassword");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress("fromemailid@gmail.com", "MyWeb Site");
mail.To.Add(new MailAddress("toemailid@gmail.com"));
mail.CC.Add(new MailAddress("ccemailid@gmail.com"));
mail.Subject = "your subject";
mail.IsBodyHtml = true;
mail.Body = "<h1>your message body</h1>";
smtpClient.Send(mail);
感谢,
这篇关于SMTP验证错误&QUOT;故障Sendng邮件&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文