您好我知道如何從smpt通過下面的mailcode發送郵件。但不知道如何從用戶的outlook.so發送郵件,用戶可以在他的郵件中找到他的郵件文件夾 請幫助我..如何從用戶的Outlook郵箱發送郵件
下面是web配置代碼發送郵件
<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>";
}
卜現在它顯示錯誤: 檢索COM類工廠CLSID組件{0006F03A-0000-0000-C000-000000000046}失敗,原因是以下錯誤:80070005次訪問被拒絕。 (來自HRESULT的異常:0x80070005(E_ACCESSDENIED))。 請幫助我
我瘦g我能想到的是BCC到預期的「發件人」,並且該用戶有一個Outlook規則將這些郵件移動到已發送郵件。我很想看看其他人提出了什麼,但 – jdphenix