【问题标题】:How to send mail from user's Outlook mailbox如何从用户的 Outlook 邮箱发送邮件
【发布时间】:2014-04-04 20:16:52
【问题描述】:

嗨,我知道如何通过下面的邮件代码从 smpt 发送邮件。但没有任何关于如何从用户的 Outlook 发送邮件的线索。这样用户就可以在他的已发送邮件文件夹中找到他的邮件 请帮帮我..

以下是发送邮件的网络配置代码

            <mailSettings>
        <smtp>
            <network host="11.111.111.1" port="25" defaultCredentials="true"/>
        </smtp>
    </mailSettings>

这是我的发送邮件方法:

        public static void SendMessage(string sbj, string bd, string bccadd, string    attachFile1,string buyeremail)
    {
        MailMessage message = new MailMessage();
        SmtpClient client = new SmtpClient();
        message.From = new MailAddress(buyeremail);
        message.To.Add(new MailAddress(bccadd));
        message.Subject = sbj.Trim();
        message.Body = bd.Trim();
        SmtpClient mysmptclient = new SmtpClient();
        mysmptclient.DeliveryMethod = SmtpDeliveryMethod.Network;


            message.Attachments.Add(new Attachment(attachFile1));
            try
            {
                message.Attachments.Add(new Attachment(attachFile5));
            }
            catch
            {
            }
                mysmptclient.Send(message);

    }

我刚刚修改了我的代码如下:

        try
        {


            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNamespace = new Outlook.NameSpace("MAPI");
            Outlook.MailItem oMailItem =  (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.HTMLBody = bd.Trim();

            oMailItem.Subject = sbj.Trim();
            Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
            Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(bccadd);
            oRecip.Resolve();
            oMailItem.Send();
            oRecip = null;
            oRecips = null;
            oMailItem = null;
            oApp = null;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
            //string script = "<script>alert('" + ex.Message + "');</script>";

        }

现在它显示错误: 由于以下错误,检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80070005 访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))。 请帮帮我

【问题讨论】:

  • 我能想到的事情是密件抄送给预期的“发件人”,并且该用户具有 Outlook 规则将这些邮件移动到已发送邮件。我很想看看其他人的想法

标签: c# asp.net


【解决方案1】:

我相信您需要使用 Outlook API 来执行此操作,因为 MailObject 和 SMTP 将使用提到的参数在内部发送邮件,这样的事情应该有助于http://www.codeproject.com/Tips/165548/C-Code-snippet-to-send-an-Email-with-attachment-fr

可能重复:Can only send email via Outlook if Outlook is open

【讨论】:

  • Microsoft 强烈反对在运行服务器进程(如 ASP.NET)时使用互操作。
  • @PatrickHofman :不知道为什么 MS 会这样做,我的几个应用程序中有代码,从近几年开始运行良好,记住它是一个桌面应用程序。
  • 问题中的标签显示 ASP.NET。请参阅this 为什么不使用互操作。
【解决方案2】:

您可以使用 Microsoft Exchange Web 服务 (EWS) 托管 API 创建和发送电子邮件。

http://msdn.microsoft.com/en-us/library/office/dd633628(v=exchg.80).aspx

MSDN 上显示的代码:

// Create an email message and identify the Exchange service.
EmailMessage message = new EmailMessage(service);

// Add properties to the email message.
message.Subject = "Interesting";
message.Body = "The merger is finalized.";
message.ToRecipients.Add("user1@contoso.com");

// Send the email message and save a copy.
message.SendAndSaveCopy();

【讨论】:

    猜你喜欢
    • 2013-04-03
    • 2022-12-13
    • 1970-01-01
    • 2011-03-12
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    相关资源
    最近更新 更多