在 C# 中更改电子邮件方向
Change Email From Direction in C#
我的 outlook 配置了 2 封电子邮件。我的个人电子邮件和邮箱。
费德里科@outlook.com
邮箱@outlook.com
已经尝试过(下面的代码),但是它从 Federico@outlook.com 而不是 Mailbox@outlook.com
发送电子邮件
private static void CreateMailItem(String to,String subject,string body)
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.To = to;
mailItem.Subject = subject;
mailItem.Body = body;
mailItem.Display(false);
mailItem.Send();
}
我认为您正在寻找 SendUsingAccount
(source) (source)
SendUsingAccount
Returns 或设置一个 Account 对象,代表发送 MailItem 所使用的帐户。 Read/write。
(继承自_MailItem)
所以只需添加:
Outlook.Account account = Application.Session.Accounts["Hotmail"]; //or however your other account is indexed in your accounts list
mail.SendUsingAccount = account;
我的 outlook 配置了 2 封电子邮件。我的个人电子邮件和邮箱。 费德里科@outlook.com 邮箱@outlook.com
已经尝试过(下面的代码),但是它从 Federico@outlook.com 而不是 Mailbox@outlook.com
发送电子邮件 private static void CreateMailItem(String to,String subject,string body)
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.To = to;
mailItem.Subject = subject;
mailItem.Body = body;
mailItem.Display(false);
mailItem.Send();
}
我认为您正在寻找 SendUsingAccount
(source) (source)
SendUsingAccount Returns 或设置一个 Account 对象,代表发送 MailItem 所使用的帐户。 Read/write。 (继承自_MailItem)
所以只需添加:
Outlook.Account account = Application.Session.Accounts["Hotmail"]; //or however your other account is indexed in your accounts list
mail.SendUsingAccount = account;