0

Hi I know how to send the mail from smpt through below mailcode.But not getting any clue on how to send mail from user's outlook.so that user can find his mails in his sent items folder Please help me..

Below is web config codes for sending the mail

 <mailSettings> <smtp> <network host="11.111.111.1" port="25" defaultCredentials="true"/> </smtp> </mailSettings> 

and this is my send mail method:

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

I just modified my code as below :

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

Bu now it shows error: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). Please help me

1
  • I thing I can think of is BCC to the intended "sender" and that user having an Outlook rule to move these messages to Sent Items. I'm interested to see what others come up with though Commented Mar 3, 2014 at 17:00

2 Answers 2

3

You can use the Microsoft Exchange Web Services (EWS) Managed API to create and send email messages.

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

Code shown on 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("[email protected]"); // Send the email message and save a copy. message.SendAndSaveCopy(); 
Sign up to request clarification or add additional context in comments.

Comments

-1

I believe you'll need to use the outlook API's to perform that, since the MailObject and SMTP will send the mail internally using the mentioned params, something like this should help http://www.codeproject.com/Tips/165548/C-Code-snippet-to-send-an-Email-with-attachment-fr

A possible duplicate : Can only send email via Outlook if Outlook is open

3 Comments

The use of interop while running a server process, like ASP.NET is strongly discouraged by Microsoft.
@PatrickHofman : Don't know why MS would do that, I have code in few of my apps, running fine from almost couple of years now, remember its an desktop app.
The tag in the question shows ASP.NET. see this why not to use interop.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.