【发布时间】:2009-07-06 07:04:54
【问题描述】:
我有一个 Asp.Net 页面,其中包含一个 GridView 和几个图像(谷歌图表 - pngs)。
我需要通过电子邮件发送我页面的内容。我怎样才能做到这一点?网格可以是电子邮件正文中的 html 表格,或者整个内容可以是图像;没关系。
感谢您的帮助!
【问题讨论】:
标签: asp.net
我有一个 Asp.Net 页面,其中包含一个 GridView 和几个图像(谷歌图表 - pngs)。
我需要通过电子邮件发送我页面的内容。我怎样才能做到这一点?网格可以是电子邮件正文中的 html 表格,或者整个内容可以是图像;没关系。
感谢您的帮助!
【问题讨论】:
标签: asp.net
您可以使用将 URL 转换为单个 MHT 文件(嵌入图像、样式表等)的库并将该文件附加到您的电子邮件中。
Here's a .NET library 完成这项工作(它是由 Jeff Atwood 编写的 ^^)
【讨论】:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Calling the function SendMail
Response.Write( SendMail("
dinesh.rabara@gmail.com ","
info@server.com","
dinesh_rabara@yahoo.com ","Test Mail","Test Mail Body"));
}
public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.server.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com ","password");
smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}
}
【讨论】:
过去我使用GridView.RenderControl 将gridview 渲染到ASP.NET 之外的文件中(在控制台应用程序中)。这可能值得研究。
编辑-我已经设法找到一个使用这种技术的人的博客文章-this may help you。
这是否适用于图像取决于您生成它们的操作。大概它们是动态生成的,可能使用 HttpHandler,或者它们是从控件生成的?
【讨论】: