Hi, i would like to programatically send the user an email of all the files they have backed up + associated file information. My question is how can i send the body in a formated way

for example

To: userEmail()
subject: File Backup Report
Body: All users files here e.g. fileName, FileType, fileSize

I can connect to the database and execute a query and set result to a string variable for the body but i would like to display the body (query results) in a neat way, aligned and ordered if possible?

Thanks for the help

MailMessage msgMail = new MailMessage();

msgMail.To = ".....";
msgMail.Cc = ".....";
msgMail.From = ".....";
msgMail.Subject = ".........";

[B]msgMail.BodyFormat = MailFormat.Html;[/B]string strBody = "<html><body><b>Hello World</b>" +
   " <font color=\"red\">ASP.NET</font></body></html>";
msgMail.Body = strBody;

SmtpMail.Send(msgMail);

Most probably you missed red marked line.

TO READ MORE YOU CAN VISIT:
http://www.4guysfromrolla.com/articles/080206-1.aspx

thanks for the advice, i will try it out!

hi, im still having problems in how to pass the results of the sql command to the email body, heres what i have so far

SqlCommand emailCommand = new SqlCommand("SELECT fileName, fileType, fileSize, fileLocation, fileDescription, Compressed, compressedSize FROM aspnet_Files WHERE fileOwner = '" + User.Identity.Name + "'", myConnection);

            string userEmail = userEmailAddress.ExecuteScalar().ToString();
            string backupReport = emailCommand.ExecuteNonQuery().ToString();
            
            MailMessage m = new MailMessage();
            m.To.Add(userEmail);
            m.From = new MailAddress("postmaster@domain.net");
            m.Subject  = "Your Personal Backup Report";
            m.Body     = backupReport;
            m.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();
            
         //   try{

             client.Send(m);
             btnEmailReport.Text = "Report Sent Successfully!";
             btnEmailReport.Font.Bold = true;
             btnEmailReport.ForeColor = System.Drawing.Color.Green;

string backupReport = emailCommand.ExecuteNonQuery().ToString();
- this line is where the problem lies (only returns one column of one row), how do i return the full results as a string to put in the mail body?

Thanks

Hi,
TRY WITH BELOW CODE. THIS IS AN EXAMPLE:

StringBuilder backupReport = new StringBuilder();
        string connectionString = ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString;
        SqlConnection conn = new SqlConnection(connectionString);
        SqlDataAdapter ad = new SqlDataAdapter("SELECT * from tblSupplier", conn);
        DataTable ds = new DataTable();
        ad.Fill(ds);
        backupReport.Append("<table border='1'><tr><td>Code</td><td>Name</td></tr>");
        foreach (DataRow oRow in ds.Rows)
            backupReport.Append("<tr><td>"+oRow["Code"]+"</td><td>"+oRow["Name"]+"</td></tr>");
        backupReport.Append("</table>");
        Response.Write(backupReport.ToString());

Dont forget to add the below directive:

using System.Text;

Happy programming............

thanks very much - your a genious!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.