[英]ASP.NET send email through 1and1 smtp
I am having issues sending an email through 1and1 smtp 我在通过1and1 smtp发送电子邮件时遇到问题
Here is my code that i use in my asp.net mvc application: (When I used this code with gmail it works fine, but now I have to use 1and1 and it won't work :( 这是我在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);
}
The error that I get is: 我得到的错误是:
SmtpException: Error in processing. The server response was: Requested action aborted: local error in processing
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, string response) System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,字符串响应)
This is my changes and now it works! 这是我的更改,现在可以使用!
Mail.from and mail.to were different addresses from the email used to login... Mail.from和mail.to是与用于登录的电子邮件地址不同的地址...
Here us the fixed code: 这是我们的固定代码:
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);
}
From 1and1 error page 从1and1错误页面
451 Requested action aborted: local error in processing:
451请求的操作中止:处理中的本地错误:
The email could not be delivered successfully because the service was temporarily unavailable.
由于该服务暂时不可用,因此无法成功发送电子邮件。 Please try again later.
请稍后再试。
Please note : For emails to be delivered successfully, it is important, among other things, that the resolution of the DNS query is always answered quickly by the responsible DNS service.
请注意 :为了使电子邮件成功传递,重要的是,负责任的DNS服务始终能够迅速回答DNS查询的解析问题。 If problems persist, you should therefore inform the administrator of the sender domain so that he can ensure a fast name resolution.
如果问题仍然存在,则应将发件人域通知管理员,以便他可以确保快速的名称解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.