C# 如何从用户发送邮件';用户的Outlook邮箱

C# 如何从用户发送邮件';用户的Outlook邮箱,c#,asp.net,C#,Asp.net,您好,我知道如何通过下面的邮件代码从smpt发送邮件。但我不知道如何从用户的outlook发送邮件。这样用户就可以在他的“已发送邮件”文件夹中找到他的邮件 请帮帮我 下面是用于发送邮件的web配置代码 <mailSettings> <smtp> <network host="11.111.111.1" port="25" defaultCredentials="true"/> &l

您好,我知道如何通过下面的邮件代码从smpt发送邮件。但我不知道如何从用户的outlook发送邮件。这样用户就可以在他的“已发送邮件”文件夹中找到他的邮件 请帮帮我

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

            <mailSettings>
        <smtp>
            <network host="11.111.111.1" port="25" defaultCredentials="true"/>
        </smtp>
    </mailSettings>
我刚刚修改了我的代码,如下所示:

        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>";

        }
试试看
{
Outlook.Application oApp=新建Outlook.Application();
Outlook.NameSpace oNamespace=新建Outlook.NameSpace(“MAPI”);
Outlook.MailItem oMailItem=(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
omalitem.HTMLBody=bd.Trim();
omalitem.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;
}
捕获(例外情况除外)
{
响应。写入(“警报(“+ex.Message+”);”;
//string script=“警报(“+ex.Message+”);”;
}
Bu现在显示错误: 由于以下错误,检索CLSID为{0006F03A-0000-0000-C000-0000000000 46}的组件的COM类工厂失败:80070005访问被拒绝。(来自HRESULT的异常:0x80070005(E_ACCESSDENIED))。
请帮助我

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

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

我相信您需要使用outlook API来执行此操作,因为MailObject和SMTP将使用所提到的参数在内部发送邮件,类似这样的操作应该会有所帮助


一个可能的重复:

我能想到的是将密件抄送给预期的“发件人”,并且该用户有Outlook规则将这些邮件移动到已发送的邮件中。我很想看看其他人是怎么想的。在运行服务器进程时使用interop,如ASP.NET,微软强烈反对。@Patrickhoffman:不知道微软为什么会这样做,我的一些应用程序中都有代码,从现在起已经运行了几年了,还记得它是一个桌面应用程序。问题中的标签显示的是ASP.NET。查看为什么不使用互操作。
// 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();