2

我有一个基于用户输入发送电子邮件的 WCF 服务。引起我注意的是,最近,某个特定用户的电子邮件在发送时没有任何正文。如果 .IsBodyHtml 设置为 true,则不传输正文;但是,如果 .IsBodyHtml 设置为 false,则正文具有相应的文本。
但是,它似乎并不一致,因为它似乎仅在所述用户的电子邮件地址设置为“发件人”地址时才会发生。

技术细节:
我们有一个 MS Exchange 邮件服务器。我正在编写一个 MailMessage 对象,将其传递给内置的 SMTP 类以发送消息。

为了简洁/清晰起见,代码已经简化了一点。尽管如此,原始代码还是非常标准/直接的。email指的是 LINQ-to-SQL 类对象

MailMessage message = new MailMessage();
message.From = new MailAddress(email.fromAddress);
message.To.Add(email.toRecipient);
message.Subject = email.emailSubject;

//set email body
message.IsBodyHtml = true;
message.Body = email.emailBody;

Attachment attachmentFile = null;
if (email.hasAttachment == true)
{
    //retrieve attachments for emailID
    var attachments = from attach in db.EmailAttachments
                      where attach.emailID == emailID
                      select attach;

    foreach (var attachment in attachments)
    {//attach each attachment
        string filePath = Path.Combine(UPLOAD_DIRECTORY, emailID.ToString(), attachment.fileName);
        attachmentFile = new Attachment(filePath);
        message.Attachments.Add(attachmentFile); //set attachment from input path
    }
}

SmtpClient client = new SmtpClient(SMTP_SERVER, SMTP_PORT); //set SMTP server name/URL and port
client.Send(message); //try to send the SMTP email
4

1 回答 1

1

由于问题与用户有关,因此很可能与该用户的设置有关。

以该用户身份登录并打开 Outlook

选择:文件 -> 选项 -> 邮件

向下滚动到“消息格式”部分

可能“选择转换为纯文本格式”将其更改为“转换为 HTML 格式”

于 2012-03-30T22:50:48.453 回答