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

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

问题描述

我使用的互操作为通过Outlook发送电子邮件,但我不能指定从E-mail地址。

我要发送邮件给多个用户从相同的发送者(来自)发起。我需要从电子邮件地址提。但是我无法找到使用智能感知的属性,让我来指定。

请帮忙。

  Microsoft.Office.Interop.Outlook.Application olkApp1 =
    新Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem olkMail1 =
    (的MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
        olkMail1.To = txtpsnum.Text;
        olkMail1.CC =;
        olkMail1.Subject =分配说明;
        olkMail1.Body =分配说明;
        olkMail1.Attachments.Add(AssignNoteFilePath,
            Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,1,
                Assignment_note);
olkMail1.Save();
//olkMail.Send();


解决方案

您使用的是Outlook来发送邮件。由于Outlook必须被配置为使用邮件的地址,你无法从提供直接解决。但是,您可以选择在Outlook中可用的帐户。例如:

 使用Outlook = Microsoft.Office.Interop.Outlook;Outlook.Accounts占= olkApp1.Session.Accounts;
的foreach(应收帐Outlook.Account)
{
    //当电子邮件地址匹配,发送邮件。
    如果(account.SmtpAddress ==from@mail.com)
    {
            olkMail1.SendUsingAccount =账户;
            ((Outlook._MailItem)olkMail1)。发送();
            打破;
    }
}

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

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.

Please help.

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();

解决方案

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天全站免登陆