我在通过1and1 smtp发送电子邮件时遇到问题
这是我在asp.net mvc应用程序中使用的代码: (当我将此代码与gmail结合使用时,它可以正常工作,但现在我必须使用1and1,它将无法正常工作:(
public void Send(Inquiry inquiry)
{
SmtpClient smtpClient = new SmtpClient ("Smtp.1and1.com", 587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("mail@mywebsite.com", "mypassword");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("sales@mywebsite.com", "myname");
mail.To.Add(new MailAddress("sales@mywebsite.com"));
mail.Subject = $"New inquiry from {inquiry.Name}";
mail.Body = $"{inquiry.Message}\r " +
$"Recieved: {inquiry.Date}";
mail.ReplyToList.Add(new MailAddress(inquiry.Email));
smtpClient.Send(mail);
}
我得到的错误是:
SmtpException: Error in processing. The server response was: Requested action aborted: local error in processing
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,字符串响应)
答案 0 :(得分:1)
这是我的更改,现在可以使用!
Mail.from和mail.to是与用于登录的电子邮件地址不同的地址...
这里是固定代码:
public void Send(Inquiry inquiry)
{
SmtpClient smtpClient = new SmtpClient ("smtp.1and1.com",587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("mail@mywebsite.com", "mypassword");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress("mail@mywebsite.com", "myname");
mail.To.Add(new MailAddress("mail@mywebsite.com"));
mail.Subject = $"New inquiry from {inquiry.Name}";
mail.Body = $"From: {inquiry.Name}\n" +
$"Phone number: {inquiry.PhoneNumber} \n" +
$"Message: {inquiry.Message}\n \n" +
$"Recieved: {inquiry.Date}";
mail.ReplyToList.Add(new MailAddress(inquiry.Email));
smtpClient.Send(mail);
}
答案 1 :(得分:0)
451请求的操作中止:处理中的本地错误:
由于该服务是 暂时不可用。请稍后再试。
请注意:要成功发送电子邮件,重要的是, 除其他事项外,DNS查询的分辨率始终是 负责的DNS服务迅速答复。如果问题仍然存在, 因此,您应该通知发件人域的管理员,以便 他可以确保快速的姓名解析。