我想知道如何设置我的 info @ *****。com 帐户,并在我的c#web API应用程序中发送电子邮件。
我配置了这样的代码:
SmtpClient client = new SmtpClient();
client.Host = "173.***.**.**";
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.EnableSsl = true;
我做错了吗?
答案 0 :(得分:0)
enableSSL可能会导致一些问题,如果正常工作,请尝试将其关闭并从那里开始。
答案 1 :(得分:0)
看来您至少错过了以下内容:
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("info@*****.com");
mailMessage.To.Add("info@*****.com");
mailMessage.Body = "body";
mailMessage.Subject = "subject";
client.Send(mailMessage);
答案 2 :(得分:0)
完整的代码应该是
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("yourmail@hotmail.com");
mail.To.Add("tomail@foo.com.br");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("yourmail@hotmail.com", "pwd");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);