Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello
i have a data table called "dt_data" contain from "ID , Name , Email " and about ten records

i need to send this as email body ... So how to do this .. ?
Can i send the as a table ?? ...
and this the way i used to send mail :

C#
MailMessage mail = new MailMessage(txt_From.Text, txt_To.Text, txt_Subject.Text, txt_Body.Text);


is there is another way to send it ??
Posted
Comments
[no name] 24-Mar-15 9:00am    
Question is not clear..?do u want to send email using c# code? or do u want to send the table inside the body?

Format the data into an HTML <table>, and send the message as HTML:
How do I send a simple Html email?[^]
 
Share this answer
 
You need to take a stringbuilder class and append html with all table format fields and pass that string builder object to mailmessage class.

Regards,
Sathish
 
Share this answer
 
Try this code..
C#
string Name="Mr Dev_Fady";
string Email = ur@email.com;//your table email id
string textBody="Hi<strong>"+UserName+"</strong><br />"+Email+" BLAH BLAH BLAH"+
"<br > BLAH BLAH BLAH <table><tr><td>BLAH BLAH BLAH</td></tr></table>";

//now pass this string to ur C# Mail class and set the message type to HTML as below:

SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress(txt_From.Text);
        smtpClient.Host = "localhost";
        message.From = fromAddress;
        message.To.Add(txt_To.Text);
        message.Subject = txt_Subject.Text;
        message.IsBodyHtml = true;
        message.Body = textBody;

        // Send SMTP mail
        smtpClient.Send(message);
 
Share this answer
 
Comments
Dev_Fady... 24-Mar-15 10:14am    
Thaaaaanks RajeeshMenoth aloot .. :)
but
if my table is like
ID Name Email
01 Fady dev fady_dev@abc.com
02 mina_dev mina_dev@abc.com
03 gad_dev gad_dev@abc.com
if the data is direct how to but it in the string builder
could i make a loop
like if i have NAme[i] and Email[i]

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