Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i wrote code to send emails to user from my application , i put TO, CC and Subject textboxes in which i mention Recepients but problem is that i can only mention 1 recepient in To and CC fields, i am just wondering that how to add multiple reciepient, like in Outlook we mention multiple recepients like with colon e.g.;;; ........................

same in CC

i have a simple text box TO in which i can put 1 address

how to do that ?


<pre lang="c#">using System.Net.Mail;
using System.Net;
using Outlook = Microsoft.Office.Interop.Outlook;

public ActionResult dailyLog(String txtEmailTo, String txtCC, String txtSubject, String txtBody) 
            if (!String.IsNullOrEmpty(Session["Admin"] as string))
                    Outlook.Application oApp = new Outlook.Application();
                    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                    oMsg.HTMLBody = txtBody;
                    //Add an attachment.
                    //String sDisplayName = "MyAttachment";
                    int iPosition = (int)oMsg.Body.Length + 1;
                    //int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    //now attached the file
                    //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
                    //Subject line
                    oMsg.Subject = txtSubject;
                    // Add a recipient.
                    Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(txtEmailTo);
                    oRecip = oRecips.Add(txtCC);
                    oRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                    // Send.
                    // Clean up.
                    oRecip = null;
                    oRecips = null;
                    oMsg = null;
                    oApp = null;
                    ViewBag.Confirmation = "Daily Has Been Log Submitted";
                    return View();
                catch (Exception ex)
                    ViewBag.Confirmation = ex.Message;
                    return View();

1 solution

Instruct your users when entering multiple email address in the TO and CC fields to separate them with either a comma or semicolon.
Share this answer
Hunain Hafeez 18-Feb-14 8:48am    
it doesn't work, it says: Outlook does not recognize one or more names.
ZurdoDev 18-Feb-14 21:13pm    
Can you use SMTP instead of Outlook then?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900