首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从用户的Outlook邮箱发送邮件

如何从用户的Outlook邮箱发送邮件
EN

Stack Overflow用户
提问于 2014-03-04 00:56:20
回答 2查看 943关注 0票数 0

嗨,我知道如何通过下面的mailcode.But从smpt发送邮件,没有得到任何关于如何从用户的outlook.so发送邮件的线索,用户可以在他的已发送邮件文件夹中找到他的邮件,请帮助我。

以下是用于发送邮件的web配置代码

代码语言:javascript
复制
            <mailSettings>
        <smtp>
            <network host="11.111.111.1" port="25" defaultCredentials="true"/>
        </smtp>
    </mailSettings>

这是我的发送邮件方法:

代码语言:javascript
复制
        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);

    }

我刚刚修改了代码,如下所示:

代码语言:javascript
复制
        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))。请帮帮我

EN

回答 2

Stack Overflow用户

发布于 2014-03-04 02:20:31

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

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

MSDN上显示的代码:

代码语言:javascript
复制
// 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();
票数 3
EN

Stack Overflow用户

发布于 2014-03-04 02:55:50

我相信您需要使用like来执行此操作,因为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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22152589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档