【问题标题】:Sent an email from asp.net through 365 with a "from" email that is different than the username通过 365 从 asp.net 发送一封电子邮件,其中的“发件人”电子邮件与用户名不同
【发布时间】:2020-01-07 13:18:46
【问题描述】:

我希望有人可以在这里帮助我:

用户通过我的 asp.net 网站生成电子邮件。电子邮件将通过 365 服务器使用我在我的域中拥有的帐户(例如 out@mydomain.com)发送出去。我希望消息“发件人”字段是我的用户的电子邮件(例如,myuser@anotherdomain.com),以便电子邮件的接收者将他的电子邮件视为发件人并直接回复他。

但是当我尝试这个时,我收到一条错误消息(见下文)。

当“发件人”字段是我域中的另一个现有邮箱(例如,myname@mydomain.com)时,即使我尝试发送电子邮件,我也会收到相同的错误消息

如果“发件人”与用户名不同,显然有人挡路(不确定是 asp.net 还是 365 服务器)阻止电子邮件。

有没有办法解决这个问题>

这是我的代码

protected void btnSend_Click(object sender, System.EventArgs e)
{
    AuditLog.Info("here");

    try
    {
        string EmailContent = "test";
        MailMessage msg = new MailMessage();
        msg.IsBodyHtml = true;
        msg.From = new MailAddress("myuser@anotherdomain.com");
        msg.Bcc.Add(msg.From);
        string email = "receiver@gmail.com";
        msg.To.Add(email);
        msg.Subject = "TEst 365";

        System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(EmailContent);
        System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(EmailContent);
        msg.AlternateViews.Add(plainTextView);
        msg.AlternateViews.Add(htmlView);
        System.Net.Mail.SmtpClient client = new SmtpClient();

        client.Host = "smtp.office365.com";
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = "out@mydomain.com", "MyPassword");
            client.Port = 587;
            client.EnableSsl = true;

            if (client.Host.Trim() != "")
                client.Send(msg);
   }
   catch (Exception ex)
   {
         AuditLog.Info(string.Format("Failed to send mail . Error={0} ",  ex.Message));
   }
   finally
   {
   AuditLog.Info("end");
   }

}


这是错误:


{"Transaction failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A00A280, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:FD1E0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:021F0000, 1.44866:14030000, 16.55847:AD0F0000, 17.43559:0000000004020000000000000000000000000000, 20.52176:140F2A8A0A00101043050000, 20.50032:140F2A8A7A17000000000000, 0.35180:48050000, 255.23226:0A00A780, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A00A880, 0.35250:0A000000, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:20000000, 1.36674:32000000, 1.61250:00000000, 1.45378:25000000, 1.44866:01000000, 16.55847:8C000000, 17.43559:0000000030030000000000007B00000000000000, 20.52176:140F2A8A0A0070200A00AD80, 20.50032:140F2A8A7A1710106B050000, 0.35180:0A00AE80, 255.23226:4800D13D, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:75050000, 4.21921:DC040000, 255.27962..."}

【问题讨论】:

    标签: asp.net email outlook


    【解决方案1】:

    就在错误消息中:Exception:SendAsDeniedException.MapiExceptionSendAsDenied;

    您需要向您的用户授予 out@mydomain.com 的 SendAs 权限。不过,这可能不是您真正想要做的,因为这些用户会使用 Office 365 许可证,如果他们正在使用许可证,他们可以自己发送。

    真正的解决方案是不使用 Office 365 作为 SMTP 中继。您应该注册另一个 SMTP 提供商,该提供商专门设置为执行您尝试执行的操作。我们使用SendGrid,但如果您搜索,还有其他的。

    【讨论】:

    • 谢谢。我现在正在从我的服务器发送,但很多电子邮件都被阻止了,我相信如果我们通过办公室服务器发送就不会发生这种情况。我可能需要寻找其他解决方案
    猜你喜欢
    • 2016-03-10
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    相关资源
    最近更新 更多