Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to using many email(which is configed) sending many customer. And i would like to receive feedback emails to mail specified in outlook, have i to do ? please! thank so much! (code by c#, asp.net)

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 21-Oct-13 22:38pm
v2
Comments
OriginalGriff 22-Oct-13 4:38am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

Hi,
Try this.
If subject and body is same for all customer then see this.
C#
string from = your registered mail;
string to = String.Empty;
string smpt = your smtp server;
string smptport = your smtp port;
DataTable dt = //get customer list in datatable from database
string SmtpUser = your smtp user(can be same as from);
string SmtpPassword = your smtp user(email) password
int totalcountofcustomer = dt.Rows.Count;
for(int i=0;i<totalcountofcustomer;i++)>
{
    to += dt.Rows[i]["CustomerEmail"] + ","; 
}
to = to.Substring(0, to.Length - 1); // Remove last extra ','
string subject = your mail subject;
string body = mail body;
MailMessage message = new MailMessage(from, to, subject, body);
message.IsBodyHtml = true; // make it false if you have plain text in body.

SmtpClient smtpClient = new SmtpClient(smpt);
smtpClient.Port = Convert.ToInt32(smptport);
smtpClient.Credentials = new System.Net.NetworkCredential(SmtpUser, SmtpPassword);
smtpClient.EnableSsl = true;
message.ReplyToList.Add(from); // customer can reply to 'from' email address
smtpClient.Send(message);

If subject and body is different on some in between logic, then see following.
C#
DataTable dt = //get customer list in datatable from database
int totalcountofcustomer = dt.Rows.Count;
string from = your registered mail;
string smpt = your smtp server;
string smptport = your smtp port;
string SmtpUser = your smtp user(can be same as from);
string SmtpPassword = your smtp user(email) password

for(int i=0;i<totalcountofcustomer;i++)>
{
    string to = String.Empty;
    to = dt.Rows[i]["CustomerEmail"]; 
    string subject = your mail subject;
    string body = mail body;
    MailMessage message = new MailMessage(from, to, subject, body);
    message.IsBodyHtml = true; // make it false if you have plain text in body.

    SmtpClient smtpClient = new SmtpClient(smpt);
    smtpClient.Port = Convert.ToInt32(smptport);
    smtpClient.Credentials = new System.Net.NetworkCredential(SmtpUser, SmtpPassword);
    smtpClient.EnableSsl = true;
    message.ReplyToList.Add(from); // customer can reply to 'from' email address
    smtpClient.Send(message);
}

Hope it helps you.
Thanks.
 
Share this answer
 
Comments
alex giulio 22-Oct-13 7:29am    
Harshil_Raval i have finished, thank so much! good luck to you!
Harshil_Raval 22-Oct-13 8:18am    
OK. Thanks. :)

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