使用Microsoft.Office.Interop.Outlook.Mailitem在C#中更改Outlook邮件发件人

时间:2014-07-31 13:02:46

标签: c# wpf email outlook mail-sender

我编写了一个wpf应用程序,它通过默认登录用户发送Outlook邮件。

这是我的代码:

using System;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace FileOrganizer
{
    class Program
    {
        private void CreateMailItem()
        {
            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.Subject = "This is the subject";
            mailItem.To = "someone@example.com";
            mailItem.Body = "This is the message.";
            mailItem.Attachment.Add(logPath);//logPath is a string holding path to the log.txt file
            mailItem.Importance = Microsoft.Office.Tools.Outlook.OlImportance.olImportanceHigh;
            mailItem.Display(false);
        }
    }
}

我看到这篇文章:

How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address

但我在项目中找不到Outlook.Accounts选项。它只是没有出现。

有没有人能解决这个问题?

我的主要目标当然是使用不同的用户发送邮件。

0 个答案:

没有答案