With Telerik I can export my grid to Excel, Word and PDF. However, is there a way to click a button open outlook and attach the grid to the email?
If that's possible, can the "To", "Subject" and "Body" be filled in with data?
I hope there is a way, thanks!
If that's possible, can the "To", "Subject" and "Body" be filled in with data?
I hope there is a way, thanks!
2 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 05 Feb 2010, 09:05 AM
Hi,
Try the code snippet below to open an outlook and passs the required data to it. You need to add a refernce to the "Microsoft.Office.Interop.Outlook.dll"
C#
Inorder to attach the grid you would need to complete the export and save the grid before attaching it to the mail.I guess you would have to do this manually to attach the grid excel to the mail.
Thanks,
Princy
Try the code snippet below to open an outlook and passs the required data to it. You need to add a refernce to the "Microsoft.Office.Interop.Outlook.dll"
C#
protected void Button1_Click(object sender, EventArgs e) |
{ |
Microsoft.Office.Interop.Outlook.Application objOutlk = new Microsoft.Office.Interop.Outlook.Application(); |
Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)objOutlk.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); |
oMailItem.To = "ToAddress"; |
oMailItem.Subject = "Your Subject"; |
oMailItem.Body = "The Mail Body"; |
oMailItem.Attachments.Add(Server.MapPath(@"Images/ExistingSheet.xls"), Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE, 1, "ExistingSheet"); |
oMailItem.Display(true); |
} |
Inorder to attach the grid you would need to complete the export and save the grid before attaching it to the mail.I guess you would have to do this manually to attach the grid excel to the mail.
Thanks,
Princy
Mike
commented on 05 Feb 2010, 02:07 PM
Top achievements
Rank 1
I'll give it a try, thank you for replying...
Daniel
commented on 08 Feb 2010, 09:46 PM
Telerik team
Hello Mike,
As mentioned in the link below, there are two common ways to send an e-mail:
1) through COM interoperability (as suggested by Princy)
2) through SMTP server
http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/2ae0167d-374a-423e-9d65-6c8079f5c013
Best regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
As mentioned in the link below, there are two common ways to send an e-mail:
1) through COM interoperability (as suggested by Princy)
2) through SMTP server
http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/2ae0167d-374a-423e-9d65-6c8079f5c013
Best regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Mike
commented on 09 Feb 2010, 01:27 PM
Top achievements
Rank 1
Oh, I have the send mail down. Now I just need to find a way to save and attached the excel spreadsheet from the grid instead of exporting it. Any ideas?
0
Accepted
Hello Mike,
The code-snippet below shows how to use the Gmail's SMTP server to send e-mail:
Best regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
The code-snippet below shows how to use the Gmail's SMTP server to send e-mail:
public
void
SendMail(
string
smtpAddress,
string
from,
string
to,
string
body,
string
subject,
bool
isHtml, Stream attachmentStream,
string
fileName)
{
SmtpClient smtpClient =
new
SmtpClient(smtpAddress);
MailMessage email =
new
MailMessage();
email.From =
new
MailAddress(from);
email.To.Add(to);
email.Body = body;
email.Subject = subject;
email.IsBodyHtml = isHtml;
smtpClient.EnableSsl =
true
;
email.Attachments.Add(
new
Attachment(attachmentStream, fileName));
NetworkCredential myCreds =
new
NetworkCredential(
"youremail@gmail.com"
,
"yourpassword"
,
""
);
smtpClient.Credentials = myCreds;
smtpClient.Send(email);
}
protected
void
RadGrid1_GridExporting(
object
source, GridExportingArgs e)
{
if
(e.ExportType == ExportType.Excel)
{
MemoryStream ms =
new
MemoryStream(
new
ASCIIEncoding().GetBytes(e.ExportOutput));
SendMail(
"smtp.gmail.com"
,
"sourcemail@gmail.com"
,
"targetmail@gmail.com"
,
"mail body"
,
"mail subject"
,
false
, ms,
"ExportedFile.xls"
);
}
Response.Redirect(Request.Url.AbsoluteUri);
}
Best regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Mike
commented on 09 Feb 2010, 04:34 PM
Top achievements
Rank 1
I can call it like this
<CommandItemTemplate> |
<asp:Button ID="ButtonEmailSummary" CommandName="ExportToExcel" Text="Send Summary Email" runat="server" /> |
</CommandItemTemplate> |
But I would like to have the alert to "Open", "Save", or "Cancel" not to popup. How can I get it to not pop-up but just send the email?
Daniel
commented on 10 Feb 2010, 03:18 PM
Telerik team
Hello Mike,
Have you tried my code-snippet? As you can see below, I cancel the export (
Let me know what your findings are.
Kind regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Have you tried my code-snippet? As you can see below, I cancel the export (
Response.Redirect
), so the response doesn't reach the browser. Let me know what your findings are.
Kind regards,
Daniel
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Mike
commented on 10 Feb 2010, 03:30 PM
Top achievements
Rank 1
Daniel,
yes, I added the response.redirect and it works. I was just hoping to stay on the page without refreshing or redirecting.
What would really be awesome is if outlooked opened the email with attachment instead of sending it. This way the user could review it before being sent and add some extra notes.
yes, I added the response.redirect and it works. I was just hoping to stay on the page without refreshing or redirecting.
What would really be awesome is if outlooked opened the email with attachment instead of sending it. This way the user could review it before being sent and add some extra notes.
Daniel
commented on 16 Feb 2010, 01:58 PM
Telerik team
Hello Mike,
yes, I added the response.redirect and it works. I was just hoping to stay on the page without refreshing or redirecting.
Unfortunately this is not possible. If you don't redirect (or end) the response, it will hit the browser and the download window will pop up.
What would really be awesome is if outlooked opened the email with attachment instead of sending it. This way the user could review it before being sent and add some extra notes.
You could try to use RadEditor to edit the letter and then attach the exported RadGrid.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
yes, I added the response.redirect and it works. I was just hoping to stay on the page without refreshing or redirecting.
Unfortunately this is not possible. If you don't redirect (or end) the response, it will hit the browser and the download window will pop up.
What would really be awesome is if outlooked opened the email with attachment instead of sending it. This way the user could review it before being sent and add some extra notes.
You could try to use RadEditor to edit the letter and then attach the exported RadGrid.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Varun
commented on 28 Dec 2022, 06:54 PM
Top achievements
Rank 1
Can it be used if the export to excel button is defined in the UI?
Attila Antal
commented on 29 Dec 2022, 10:45 AM
Telerik team
Hi Varun,
You can command the Grid to export its content by calling the fireCommand() javascript function (e.g. fireCommand("ExportToPdf", "")). See fireCommand for more details.
Be sure that the Button is not making any PostBacks. The Grid will do the PostBack as soon as it receives the command.
Varun
commented on 04 Jan 2023, 06:31 PM
| edited
Top achievements
Rank 1
Does the proxyurl thing work in kendogrid??
Attila Antal
commented on 05 Jan 2023, 08:18 AM
Telerik team
Hi Varun,
You can submit this question in the Kendo UI for jQuery Forum.
Have much the same question.
Mine however, after saving the pdf ex grid to file, ideally needs to open a RadWindow (my email.aspx page), such that I can use my smtp mailer, and attach the saved pdf file. No Rocket science stuff here, all is done
BUT, I would like to preserve my original RadGrid Screen or refresh it , and then probably best by jscript in the page's onactivate event, given a server side set varaible (the usual <%= boolvar %> scenario, invoke the radwindow.
It's just that , I would really like to once the pdf file is saved, return to the browser, same grid page as which made the pdf file and continue normally
Any ideas / help would be appreciated.
Thanks
Neal
It's just that , I would really like to once the pdf file is saved, return to the browser, same grid page as which made the pdf file and continue normally
You have two options:
- let the user save the file (e.g. use the default browser save as dialog)
- persist your settings and then use Response.Redirect to refresh the page
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.