【问题标题】:Exchange server blocks emails with embedded imagesExchange 服务器阻止带有嵌入图像的电子邮件
【发布时间】:2017-12-18 17:04:05
【问题描述】:

很遗憾,由于我们的交换服务器提供商进行了更新,我们无法再发送带有嵌入图像的电子邮件。

我们一发送电子邮件,就会收到以下错误:“远程服务器返回错误:(401) Unauthorized。” 如果我们从电子邮件中删除图像,一切正常。 有没有办法解决这个问题?

我们的 c# 代码:

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
LinkedResource imagelink;
MatchCollection matches = Regex.Matches(Body, "<img.*?src=\"cid:(.*?)\"");
foreach (Match match in matches)
{
    myHttpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(match.Groups[1].Value));

    myHttpWebRequest.UseDefaultCredentials = true;
    myHttpWebRequest.PreAuthenticate = true;
    myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;

    using (myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse())
    {
        receivedStream = myHttpWebResponse.GetResponseStream();

        MemoryStream streamReceivedCopy = new MemoryStream();                       
        ImageUtils.CopyStream(receivedStream,streamReceivedCopy);
        var imageType = ImageUtils.GetImageMIMEType(streamReceivedCopy);
        streamReceivedCopy.Position = 0;
        imagelink = new LinkedResource(streamReceivedCopy, imageType);
        imagelink.ContentId = match.Groups[1].Value;
        imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
        htmlView.LinkedResources.Add(imagelink);
    }
}
mail.AlternateViews.Add(htmlView);

然后我们使用 .net SmtpClient 发送电子邮件

【问题讨论】:

    标签: .net image exchange-server


    【解决方案1】:

    我们设法找到了错误:它只是一个正在部署的旧库导致错误。 旧库缺少这些代码行

    myHttpWebRequest.UseDefaultCredentials = true;
    myHttpWebRequest.PreAuthenticate = true;
    myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
    

    对不起! :(

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 2012-04-07
      • 2017-06-16
      • 1970-01-01
      • 2011-05-18
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      相关资源
      最近更新 更多