Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
how to send gridview data in outlook mail body in C#

XML
outlook.Application oApp = new outlook.Application();


                outlook.MailItem oMsg = (outlook.MailItem)oApp.CreateItem(outlook.OlItemType.olMailItem);
                outlook.Inspector oInspector = oMsg.GetInspector;
                oMsg.HTMLBody = "Dear Sir, <br/> Please Assign the Priority for Scaffolding Jobs...!!<br/>";

oMsg.Subject = "New Request from Scaffolding Jobs";
outlook.Recipients oRecips = (outlook.Recipients)oMsg.Recipients;
outlook.Recipient oRecip = (outlook.Recipient)oRecips.Add("Safihur@fabtech.ae");

oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
Posted
Comments
[no name] 7-Jun-14 8:47am    
You would have to write some code to put the data in the body of your message.
safihur Rahuman 7-Jun-14 8:52am    
ya pls give me some idea how to put data inthe body..
[no name] 7-Jun-14 18:37pm    
You are kidding right? The body is a string. Don't you know how to assign data to a string?

1 solution

try below
C#
StringBuilder emailBody = new StringBuilder();
StringWriter sw = new StringWriter(emailBody);
HtmlTextWriter hw = new HtmlTextWriter(sw);
gridView1.RenderControl(hw);
oMsg.HTMLBody = "Dear Sir, <br /> Please Assign the Priority for Scaffolding Jobs...!!<br />" +
emailBody.ToString();


check below post for how you could generate html from gridview.
How to Send Gridview in Email Body in Asp.Net Using C#, VB.NET[^]
check below KB article
How to use the Microsoft Outlook Object Library to send an HTML formatted message by using Visual C#[^]
 
Share this answer
 
v2

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