anjumathi kumar

anjumathi kumar

  • NA
  • 54
  • 64k

How to write code with semicolon in recepient while sending email

Aug 31 2011 2:22 AM

Hi this is my coding for sending an email

I want to send a recepient as like

[email protected];[email protected];[email protected]
[email protected],[email protected]

like in recepients i want to put semicolon or comma but both want to accept in coding..how to do this any idea?

Collapse | Copy Code
protected static string mailSend(string FromAddress,string password,string[] ToAddress,string[] CcAddress,string[] BccAddress,string MessageBody,string Subject,string[] FileAttachment)
{
try
{
MailMessage obj = new MailMessage();
SmtpClient serverobj = new SmtpClient();

serverobj.Credentials = new NetworkCredential(FromAddress, Password);
serverobj.Port = 25;
serverobj.Host = "smtp.gmail.com";
serverobj.EnableSsl = true;
obj = new MailMessage();
obj.From = new MailAddress(FromAddress, FromAddress, System.Text.Encoding.UTF8);
obj.Priority = MailPriority.High;
obj.Subject = Subject.Trim();
string date = DateTime.Now.ToString();
obj.Body = MessageBody;
obj.IsBodyHtml = true;


if (ToAddress != null)
{
foreach (string toAddr in ToAddress)
obj.To.Add(new MailAddress(toAddr));
}



if (CcAddress != null)
{
foreach (string ccAddr in CcAddress)
obj.CC.Add(new MailAddress(ccAddr));
}
else
CcAddress = null;



if (BccAddress != null)
{
foreach (string bccAddr in BccAddress)
obj.Bcc.Add(new MailAddress(bccAddr));
}
else
BccAddress = null;


if (Subject == string.Empty)
Subject = string.Empty;

if (MessageBody == string.Empty)
MessageBody = string.Empty;


if (Attachments != null && Attachments.Length > 0)
foreach (string _Attachment in Attachments)
obj.Attachments.Add(new System.Net.Mail.Attachment(_Attachment));
else
Attachments = null;



dbquery.InsertMail(FromAddress, ToAddress, CcAddress, BccAddress, Subject, MessageBody, Attachments);
serverobj.Send(obj);
return "Mail Sent Successfully";
}

catch (Exception ex)
{
return ex.Message;
}
}

Answers (2)