gpt4 book ai didi

email - 使用 EWS API 发送电子邮件时控制消息编码

转载 作者:行者123 更新时间:2023-12-05 07:50:26 24 4
gpt4 key购买 nike

我正在使用 Microsoft EWS(Exchange 网络服务)向外部客户发送电子邮件(关于支持电话)。

我们的一位客户正在尝试将电子邮件正文自动导入他们自己的支持调用系统(我认为这是基于 JAVA 的),但他们不断收到此异常:

不支持的编码异常:iso-8859-10

所以他们让我把它改成UTF8

如果我从我的 Outlook(它是同一 Exchange 的客户端)向他们发送电子邮件,它工作正常。它仅在通过 EWS 发送时发生。

这是我的代码:

 protected void SendEmail2(string recipientsAddresses, string senderAddress, string ccRecipients, string subject, string body, bool CCToSender, bool simulate, Importance messageImportance)
{
ExchangeService service = null;
EmailMessage message = null;

try
{
// initialize a proxy to the exchange web services
service = new ExchangeService(MAGMA_EXCHAGE_VERSION);
service.Url = new Uri(MAGMA_EWS_URI);

// create the message
message = new EmailMessage(service);

// Add recipients
foreach (string recipientEmail in recipientsAddresses.Split(";".ToCharArray()))
{
message.ToRecipients.Add(new EmailAddress(recipientEmail));
}

// handle inline images
body = AddInlineImages(message, body);

// set everything
message.From = new EmailAddress(senderAddress);
message.Subject = subject;
message.Body = new MessageBody(BodyType.HTML, body);
message.Importance = messageImportance;

// and send
message.Save();
FolderId SentFolderForUser = new FolderId(WellKnownFolderName.SentItems, senderAddress);
message.SendAndSaveCopy(SentFolderForUser);
}
catch (Exception)
{
throw;
}
}

我传递给“正文”的字符串是一个包含以下内容的 HTML:

标题下的

meta charset="utf-8" 标签。

这里有什么我遗漏的吗?

谢谢,吉尔。

最佳答案

您可能希望重新编码并使用类似下面的内容来设置编码:

$ews = new ExchangeWebServices($host, $user, $password, ExchangeWebServices::VERSION_2007_SP1);
$msg = new EWSType_MessageType();
$msg->MimeContent = new EWSType_MimeContentType();
$msg->MimeContent->_ = base64_encode("Mime-Version: 1.0\r\n"
. "From: michael@contoso.com\r\n"
. "To: amy@contoso.com\r\n"
. "Subject: nothing\r\n"
. "Date: Tue, 15 Feb 2011 22:06:21 -0000\r\n"
. "Message-ID: <{0}>\r\n"
. "X-Experimental: some value\r\n"
. "\r\n"
. "I have nothing further to say.\r\n");
$msg->MimeContent->CharacterSet = 'UTF-8';

另外看看这个 question here,因为它看起来很相似。

注意:这是一个很好的 starting point regarding the content-type encoding 选项。您还可能希望查看官方 Microsoft howto here

关于email - 使用 EWS API 发送电子邮件时控制消息编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36156628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com