如果满足某些条件,我将尝试从我的 ASP.NET 网页发送电子邮件。
这是我的代码。
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential =
new NetworkCredential("username", "password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("[email protected] /cdn-cgi/l/email-protection");
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("[email protected] /cdn-cgi/l/email-protection");
try
{
smtpClient.Send(message);
}
catch(Exception ex)
{
//Error, could not send the message
Response.Write(ex.Message);
}
我还没有分享服务器详细信息。我正在尝试从我的 Outlook 电子邮件地址发送它。但是,我不断收到错误:邮件发送失败.
试试这个代码
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected] /cdn-cgi/l/email-protection", "yourPassword");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress("[email protected] /cdn-cgi/l/email-protection", "MyWeb Site");
mail.To.Add(new MailAddress("[email protected] /cdn-cgi/l/email-protection"));
mail.CC.Add(new MailAddress("[email protected] /cdn-cgi/l/email-protection"));
mail.Subject = "your subject";
mail.IsBodyHtml = true;
mail.Body = "<h1>your message body</h1>";
smtpClient.Send(mail);
thanks,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)