我正在使用显示RadGrid
的{{1}},当我在浏览器中打开此页面时,它运行正常。但是当我通过电子邮件发送此网格并在Outlook中打开时,我的网格总数将显示在项目上方。
请参阅以下与Outlook中我的问题相关的屏幕截图
在浏览器(Firefox)中看起来很好。但是当我检查渲染的HTML时,页脚HTML位于Header和Body之间。
我的示例代码:
Footer = true
答案 0 :(得分:2)
试试这个漂亮的小选项:
下面的代码段显示了如何使用Gmail的SMTP服务器发送电子邮件:
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);
}
请注意导出是如何“取消”的,但包含导出的“文件”的内存流会作为附件添加到电子邮件中。 Taken from here
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);
}
或者,如果您只想获取html并将其发送到电子邮件中,请尝试以下操作:Taken from here
<telerik:RadGrid ID="RadGrid1" Skin="Black" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource1">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="Subject" HeaderText="Subject">
</telerik:GridBoundColumn>
</Columns>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
</MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send email - grid" />
protected void RadGrid1_NeedDataSource1(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
List<MailMessage> mList = new List<MailMessage>();
MailMessage m1 = new MailMessage();
m1.Subject = "One";
mList.Add(m1);
MailMessage m2 = new MailMessage();
m2.Subject = "Two";
mList.Add(m2);
MailMessage m3 = new MailMessage();
m3.Subject = "Three";
mList.Add(m3);
RadGrid1.DataSource = mList;
}
protected void Button1_Click(object sender, EventArgs e)
{
string GridRawHtml;
StringWriter stringWriter = new StringWriter();
HtmlTextWriter clearWriter = new HtmlTextWriter(stringWriter);
RadGrid1.RegisterWithScriptManager = false;
RadGrid1.RenderControl(clearWriter);
GridRawHtml = clearWriter.InnerWriter.ToString();
GridRawHtml = GridRawHtml.Remove(GridRawHtml.IndexOf("<script"), GridRawHtml.LastIndexOf("</script>") - GridRawHtml.IndexOf("<script"));
Response.Write(GridRawHtml);
}
答案 1 :(得分:1)
这很可能是因为Telerik的控件使用了大量的JavaScript和嵌入式资源(=很多CSS)。正如@sine在您的问题评论中所说,这些控件显然不是为电子邮件的可交付性/可移植性而设计的。 可能有一些JS管理网格的页脚位置,JS不会包含在Outlook邮件中(你应该在Telerik的论坛上提出问题以确定这一点)。
你应该考虑另一种以更“电子邮件”友好格式生成网格的方法,因为这种HTML通常还带有可交付性/垃圾邮件检查问题。