MailMessage mail = new MailMessage(from, to);
mail.Subject = "Proba email";
mail.Attachments.Add(new Attachment("C:\\Documents and Settings\\Proba.txt"));
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Port = 587; // 465 568
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("smg@hotmail.com", "password");
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
client.SendAsync(mail, "token");
使用,Async我实际上没有错误,我甚至得到反馈说消息发送(事件触发器)但消息永远不会到达。如果我使用简单的client.Send void,我收到以下错误:
5.3.4未采取请求的行动;要继续发送邮件,请登录您的帐户。
那么关于问题可能是什么的任何想法?当我试图传递hotmail的SMTP设置时,我得到了各种设置,说端口25,然后587所以也许它就是那里的东西。非常感谢任何帮助,谢谢!
答案 0 :(得分:5)
这是我的设置,BTW async不会返回任何错误。
<system.net>
<mailSettings>
<!-- E-mail server settings -->
<smtp from="do-not-reply@example.com">
<network host="smtp.example.com" port="25" userName="" password="" defaultCredentials="true" />
</smtp>
</mailSettings>
void SendEmail(EmailEntity email)
{
var mailMessage = new MailMessage { From = new MailAddress(email.From) };
mailMessage.To.Add(new MailAddress(email.To));
mailMessage.Subject = email.Subject;
mailMessage.Body = email.Body;
mailMessage.IsBodyHtml = true;
// Send the email
var client = new SmtpClient();
client.Send(mailMessage);
}
答案 1 :(得分:2)
我有一个类似的设置,我只使用适合我的Send()。我唯一的额外补充是
client.DeliveryMethod = SmtpDeliveryMethod.Network;
在client.Send();
之前。不确定这是否能解决您的问题。您是否使用相同的服务器和凭据进行Outlook设置?
答案 2 :(得分:0)
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
// System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
MailAddress fromAddress = new MailAddress(txt_name.Text, txt_to.Text);
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 25;
// msg.From = new System.Net.Mail.MailAddress("xyz@gmail.com");
message.From = fromAddress;
message.To.Add("xyz111@gmail.com");
message.Body = txt_des.Text;
smtpClient.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "xyz@gmail.com";
NetworkCred.Password = "xtz";
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = NetworkCred;
smtpClient.Send(message);
lblStatus.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblStatus.Text = "Send Email Failed." + ex.Message;
}