Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29762

How do you add multiple recipients to an e-mail sent via Microsoft.Office.Interop.Outlook.Application?

$
0
0

I am uploading a database every day. Whenever the upload is done, the program should automatically send an e-mail to certain recipients. My Outlook is 2013 Professional Plus.

using Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;


 OutlookApp outlookApp = new OutlookApp();

                // Create a new mail item.
                //Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);

                // Set HTMLBody. 
                //add the body of the email

                mailItem.HTMLBody = "Prezados, a base " + Produto + " foi atualizada.<br>"
                    + "Data e hora local do upload: " + localDate.ToString("en-GB") +"" + localDate.Kind + "<br>"
                    + "Email gerado automaticamente."
                    ;
                //Subject line
                //oMsg.Subject =
                mailItem.Subject = "Atualização diária da base " + Produto

The code Works so far. Beyond this, i don't know how to properly structure it or call the functions to send an email to the desired recipients.

The remaining code you will see in the next panel uses a structure that i previously scrapped, that worked with Outlook 2010. I need to adapt this next part to function with my new code compatible with Outlook 2013, but i have no idea how to do it

                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;



                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email_template@x.com");
                Outlook.Recipient oRecip1 = (Outlook.Recipient)oRecips.Add("email_template@x.com");
                Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("email_template@x.com");
                Outlook.Recipient oRecip3 = (Outlook.Recipient)oRecips.Add("email_template@x.com");

                oRecip.Resolve();
                oRecip1.Resolve();
                oRecip2.Resolve();
                oRecip3.Resolve();

                // Send.
                oMsg.Send();
                // Clean up.
                oRecip = null;
                oRecip1 = null;
                oRecip2 = null;
                oRecip3 = null;

                oRecips = null;
                oMsg = null;
                oApp = null;

Viewing all articles
Browse latest Browse all 29762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>