嗨,我知道如何通过下面的mailcode.But从smpt发送邮件,没有得到任何关于如何从用户的outlook.so发送邮件的线索,用户可以在他的已发送邮件文件夹中找到他的邮件,请帮助我。
以下是用于发送邮件的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>";
}但是现在它显示错误:为CLSID为{0006F03A-0000-0000-C000-000000000046}的组件检索COM类工厂失败,因为出现以下错误: 80070005访问被拒绝。(来自HRESULT的异常: 0x80070005 (E_ACCESSDENIED))。请帮帮我
发布于 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上显示的代码:
// 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();发布于 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有所帮助。
https://stackoverflow.com/questions/22152589
复制相似问题