| | |
populate email with data from database
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 41
Reputation:
Solved Threads: 0
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
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 = ".........";
msgMail.BodyFormat = MailFormat.Html;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
Last edited by peter_budo; Apr 12th, 2009 at 8:38 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Oct 2008
Posts: 41
Reputation:
Solved Threads: 0
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
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
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
Last edited by julseypart; Apr 12th, 2009 at 1:49 pm.
Hi,
TRY WITH BELOW CODE. THIS IS AN EXAMPLE:
Dont forget to add the below directive:
Happy programming............
TRY WITH BELOW CODE. THIS IS AN EXAMPLE:
c# Syntax (Toggle Plain Text)
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:
c# Syntax (Toggle Plain Text)
using System.Text;
Happy programming............
![]() |
Similar Threads
- retrive data on same jsp page (JSP)
- VB6 ACCESS database Connection Query (Visual Basic 4 / 5 / 6)
- populate two dropdownlist (C#)
- Need Developer: mysql and associated pages (Web Development Job Offers)
- Extracting data from large SINGLE-table database to MULT-table relational database (MySQL)
- datagrid (VB.NET)
- Product List and Order Form Submit (JavaScript / DHTML / AJAX)
Other Threads in the ASP.NET Forum
- Previous Thread: text box validataion
- Next Thread: Error: Your Login attempt was not succesful. please try again
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose feedback flash flv form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols radio ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webarchitecture webdevelopemnt webservice xml youareanotmemberofthedebuggerusers





