Click here to Skip to main content
16,022,737 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
How to send mail that contains data from sql database that should be attached to body. Please anyone help me now.
Posted

1 solution

Just Read the data from DB and set it as MailMessage.Body Property.

You have to use Following namespace,

Using System.Net.Mail


Sample Code :

MailMessage Mail = new MailMessage();<br />        MailAddress mailAdd = new MailAddress(txtFrom.Text,txtName.Text);<br />        Mail.From = mailAdd ;<br />        Mail.To.Add(txtTo.Text);<br />        Mail.Subject = txtSubject.Text;<br />        Mail.Body = ReadMailBody(); // Read data from Database<br />       try<br />        {<br />            SmtpClient Objsmtp = new SmtpClient();<br />	    Objsmtp .Host = "myMailServer"; <br />            Objsmtp .Send(Mail);<br />          <br />        }<br />        catch (Exception ex)<br />        {<br />            //Handel Exception<br />        }


 
Share this answer
 


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