小编Rob*_*Rob的帖子

从指定的Outlook帐户发送电子邮件

我正在使用Outlook2013,它有来自交换服务器和pop服务器的多个邮箱.(Rob@mydomain.com [默认交换],rob @ somethingdifferent.com [POP],support@mydomain.com [交换])

我正在尝试使用Outlook自动化使用support@mydomain.com帐户发送电子邮件.

我遇到的问题是下面的代码在支持发件箱中创建了一个邮件项目,但是from字段是rob@mydomain.com而不是support@mydomain.com.这会阻止它被发送.

我想将发件人地址更改为support@mydomain.com.我认为通过设置Sendusingaccount属性就可以了.

任何帮助是极大的赞赏.

    public static string Send_Email_Outlook(string _recipient, string _message, string _subject, string _cc, string _bcc, string accountname)
    {
        try
        {

            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

            // Get the NameSpace and Logon information.
            Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

            // Log on by using a dialog box to choose the profile.
            oNS.Logon(Missing.Value, Missing.Value, true, true);

            // Create a new mail item.
            Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            // Set the subject.
            oMsg.Subject = _subject;

            // Set HTMLBody. …
Run Code Online (Sandbox Code Playgroud)

c# email outlook mailitem office-interop

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

email ×1

mailitem ×1

office-interop ×1

outlook ×1