Is Outlook changing body format after attaching to ApplicationEvents_11_ItemSendEventHandler and why if so?

huangapple go评论66阅读模式
英文:

Is Outlook changing body format after attaching to ApplicationEvents_11_ItemSendEventHandler and why if so?

问题

我注意到当我执行以下操作时,电子邮件格式发生了更改:

private void button1_Click(object sender, RibbonControlEventArgs e)
{
  //var mail = new MailForm();
  //mail.ShowDialog();

  Outlook.Application outlookApp = Globals.ThisAddIn.Application;
  outlookApp.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApp_ItemSend);

  try
  {
    Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
    Outlook.UserProperty mailUserProperty = mailItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);
    mailUserProperty.Value = "This is from my procedure";

    mailItem.Display(true); // Pass 'true' to make the window modal

    outlookApp.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApp_ItemSend);

  }
  catch (System.Exception ex)
  {
    Forms.MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  }

}

我的Thunderbird客户端收到的电子邮件内容如下:

X-MS-TNEF-Correlator: 000000006369751F17599447AC12B6C7A882F623A4732100

------=_NextPart_000_0001_01D9BE1B.AE7FB620
Content-Type: application/ms-tnef;
    name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
    filename="winmail.dat"

而在不侦听ItemSend事件的常规电子邮件的电子邮件内容如下:

------=_NextPart_000_0005_01D9BE1B.B597D000
Content-Type: text/html;
    charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

似乎在将ItemSend事件附加到电子邮件之前/之后有些东西会更改电子邮件内容。有人能确认吗?

更新

我稍微查看了一下,找到了这个陈述:

如何控制消息中的TNEF

您可以使用以下三种方法来控制TNEF:

全局 - 如果将默认电子邮件格式更改为纯文本或HTML,它有助于确保TNEF不会被发送,除非Outlook需要它

如何控制消息中的TNEF

是不是这个: "除非Outlook需要它"?

英文:

I have noticed that the email formatting was changed when I do this:

private void button1_Click(object sender, RibbonControlEventArgs e)
{
  //var mail = new MailForm();
  //mail.ShowDialog();

  Outlook.Application outlookApp = Globals.ThisAddIn.Application;
  outlookApp.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApp_ItemSend);

  try
  {
    Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
    Outlook.UserProperty mailUserProperty = mailItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);
    mailUserProperty.Value = "This is from my procedure";

    mailItem.Display(true); // Pass 'true' to make the window modal

    outlookApp.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApp_ItemSend);

  }
  catch (System.Exception ex)
  {
    Forms.MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  }

}

The email that comes to my Thunderbird client has this:

X-MS-TNEF-Correlator: 000000006369751F17599447AC12B6C7A882F623A4732100


------=_NextPart_000_0001_01D9BE1B.AE7FB620
Content-Type: application/ms-tnef;
	name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="winmail.dat"

And here is the email content of the regular email (without listening to ItemSend event)

------=_NextPart_000_0005_01D9BE1B.B597D000
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

It seems that something is changing the email content after/before ItemSend event is attached to it. Can anyone confirm this?

UPDATE

I looked around a bit and found this statement:

> How to control TNEF in messages
>
> You can control TNEF by using one of three methods:
>
> Global - If you change your default email format to plain text or
> HTML, it helps make sure that TNEF is not sent unless an Outlook
> feature needs it
.

How to control TNEF in messages

Can it be it: "unless an Outlook feature needs it"?

答案1

得分: 1

如果您设置了用户属性,Outlook 将切换到 TNEF,因为在纯 MIME 消息中无法保留它。

如果您需要设置自定义属性而不强制使用 TNEF/RTF 格式,请使用 MailItem.PropertyAccessor.SetProperty 进行设置。您可以使用与使用 UserProperties.Add 时生成的 DASL 属性名称相同的名称。您可以在 OutlookSpy(我是它的作者)中看到 DASL 属性名称 - 选择具有用户属性的已发送消息,单击 IMessage 按钮,选择属性,查看 DASL 编辑框。

英文:

If you set a user property, Outlook will switch to TNEF since it is otherwise impossible to preserve it in a pure MIME message.

If you need to set a custom property without forcing TNEF/RTF format, set it using MailItem.PropertyAccessor.SetProperty. You can use the same DASL property name as the one generated when you used UserProperties.Add. You can see the DASL property name in OutlookSpy (I am its author) - select the sent message with the user property, click IMessage button, select the property, see DASL edit box.

答案2

得分: 0

问题实际上是由于该电子邮件的用户属性造成的:

Outlook.UserProperty mailUserProperty = mailItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);
mailUserProperty.Value = "This is from my procedure";

在我删除了这些代码行之后,一切都恢复如旧。

英文:

Actually, the problem was because of the user property on that email:

  Outlook.UserProperty mailUserProperty = mailItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);
    mailUserProperty.Value = "This is from my procedure";

After I removed these lines of code everything is as before.

huangapple
  • 本文由 发表于 2023年7月24日 17:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定