如何从 C# 更改后期绑定 Outlook 邮件中的发件人
How to change Sender in late binding Outlook Mail from c#
我想使用后期绑定通过 Outlook 发送电子邮件。到目前为止它工作正常,但我想使用另一个 "FROM" 地址,而不是我的 outlook 帐户使用的地址。
有人知道怎么做吗?
通过尝试早期绑定,我发现了一些属性 "Sender"、"SenderEmailAdress" ...但对我没有任何作用,或者我做错了 ...(我认为是)
这是我创建邮件和打开 outlook 的代码。
try
{
CreateObject co = new CreateObject("Outlook.Application");
object[] parms = new object[1];
parms[0] = 0;
object mailitem = co.Execute("CreateItem", parms);
// define TO
object recipients = mailitem.GetType().InvokeMember("Recipients", BindingFlags.GetProperty, null, mailitem, null);
object[] address = new object[1];
address[0] = toAdress;
recipients.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, recipients, address);
// define subject
parms[0] = subject;
mailitem.GetType().InvokeMember("Subject", BindingFlags.SetProperty, null, mailitem, parms);
// define MailText
parms[0] = mailText;
mailitem.GetType().InvokeMember("Body", BindingFlags.SetProperty, null, mailitem, parms);
// open Outlook to send manually
mailitem.GetType().InvokeMember("Display", BindingFlags.InvokeMethod, null, mailitem, null);
}
catch (Exception ex)
{
throw;
}
您只能更改 SentOnBehalfOfName 属性; Sender 和 SenderEmailAddress 是只读属性。如果您需要使用不同的发件人发送,则需要将 SendUsingAccount 属性 设置为代表为该发件人配置的帐户的帐户对象。
我想使用后期绑定通过 Outlook 发送电子邮件。到目前为止它工作正常,但我想使用另一个 "FROM" 地址,而不是我的 outlook 帐户使用的地址。 有人知道怎么做吗?
通过尝试早期绑定,我发现了一些属性 "Sender"、"SenderEmailAdress" ...但对我没有任何作用,或者我做错了 ...(我认为是)
这是我创建邮件和打开 outlook 的代码。
try
{
CreateObject co = new CreateObject("Outlook.Application");
object[] parms = new object[1];
parms[0] = 0;
object mailitem = co.Execute("CreateItem", parms);
// define TO
object recipients = mailitem.GetType().InvokeMember("Recipients", BindingFlags.GetProperty, null, mailitem, null);
object[] address = new object[1];
address[0] = toAdress;
recipients.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, recipients, address);
// define subject
parms[0] = subject;
mailitem.GetType().InvokeMember("Subject", BindingFlags.SetProperty, null, mailitem, parms);
// define MailText
parms[0] = mailText;
mailitem.GetType().InvokeMember("Body", BindingFlags.SetProperty, null, mailitem, parms);
// open Outlook to send manually
mailitem.GetType().InvokeMember("Display", BindingFlags.InvokeMethod, null, mailitem, null);
}
catch (Exception ex)
{
throw;
}
您只能更改 SentOnBehalfOfName 属性; Sender 和 SenderEmailAddress 是只读属性。如果您需要使用不同的发件人发送,则需要将 SendUsingAccount 属性 设置为代表为该发件人配置的帐户的帐户对象。