如何通过指定发件人地址使用 Microsoft.Office.Interop.Outlook.MailItem 发送邮件 [英] How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address

查看:39
本文介绍了如何通过指定发件人地址使用 Microsoft.Office.Interop.Outlook.MailItem 发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Interop 通过 Outlook 发送电子邮件,但我无法指定发件人电子邮件地址.

I'm using Interop for sending e-mails via Outlook, but I am not able to specify the From e-mail address.

我想向来自同一个发件人(来自)的多个用户发送邮件.我需要提及发件人的电子邮件地址.但是,我无法使用 Intellisense 找到允许我指定它的属性.

I want to send mails to multiple users originating from the same sender (from). I need to mention the from e-mail address. However I cannot find a property using Intellisense that allows me to specify it.

请帮忙.

Microsoft.Office.Interop.Outlook.Application olkApp1 = 
    new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem olkMail1 =
    (MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
        olkMail1.To = txtpsnum.Text;
        olkMail1.CC = "";
        olkMail1.Subject = "Assignment note";
        olkMail1.Body = "Assignment note";
        olkMail1.Attachments.Add(AssignNoteFilePath, 
            Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, 
                "Assignment_note");
olkMail1.Save();
//olkMail.Send();

推荐答案

您正在使用 Outlook 发送邮件.由于 Outlook 必须配置为使用邮件的 from 地址,因此您不能直接提供 from 地址.但是,您可以选择 Outlook 上可用的帐户.例如:

You are using outlook to send the mail. Since outlook must be configured to use the from address of your mail, you cannot provide the from address directly. However, you can select an account available on outlook. For example :

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Accounts accounts = olkApp1.Session.Accounts;
foreach (Outlook.Account account in accounts)
{
    // When the e-mail address matches, send the mail.
    if (account.SmtpAddress == "from@mail.com")
    {
            olkMail1.SendUsingAccount = account;
            ((Outlook._MailItem)olkMail1).Send();
            break;
    }
}

这篇关于如何通过指定发件人地址使用 Microsoft.Office.Interop.Outlook.MailItem 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆