我正在使用我们公司的SMTP服务器发送邮件。当我发送邮件到其他邮件(公司域外)时,我遇到了问题,返回错误:
“服务器拒绝了一个或多个收件人地址。服务器 回复是550 5.7.1无法转发“。
如果邮件在公司内,则没有错误并且邮件发送成功。我的Web应用程序托管在IIS中。
答案 0 :(得分:1)
我会假设您的代码没有任何问题。我想这是一个配置问题,即SMTP服务器配置为不向不属于您公司域的地址发送电子邮件。如果是这样,您需要咨询Windows /网络团队以确认在SMTP服务器级别应用的配置。
答案 1 :(得分:1)
我解决了这个问题。要使用此代码,您需要添加名称空间使用System.Web.Mail;
源代码:
MailMessage mail = new MailMessage();
mail.To = "yourfromemail@domain.com";
mail.From = "yourtodomain@domain.com";
mail.Subject = "Email test.";
mail.Body = "Your body text here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.Send( mail );
//您需要将本地主机地址添加到IIS管理器。 转到IIS管理器 - >默认SMTP服务器 - >属性 - >访问 - >继电器 - >仅允许从以下列表中获取 - >添加 - > 127.0.0.1 - >单击“确定”