【发布时间】: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 规则将这些邮件移动到已发送邮件。我很想看看其他人的想法