【发布时间】:2011-07-05 04:54:53
【问题描述】:
我需要发送一封包含异常详细信息(黄屏死机)作为附件的邮件。
我可以按如下方式获得 YSOD:
string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
if (!string.IsNullOrEmpty(YSODmarkup))
{
Attachment YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.htm");
mm.Attachments.Add(YSOD);
}
mm 的类型为MailMessage,但邮件未发送。
这里
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("from", "to", "Exception-Details", htmlEmail.ToString());
用于绑定邮件正文。
在此之后仅添加附件。 删除附件时,会发送邮件。
谁能帮帮我?
根据 Albin 先生和 Paul 先生的 cmets 正在更新以下内容
string YSODmarkup = Ex_Details.GetHtmlErrorMessage();
string p = System.IO.Directory.GetCurrentDirectory();
p = p + "\\trial.txt";
StreamWriter sw = new StreamWriter(p);
sw.WriteLine(YSODmarkup);
sw.Close();
Attachment a = new Attachment(p);
if (!string.IsNullOrEmpty(YSODmarkup))
{
Attachment YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.html");
System.Net.Mail.Attachment(server.mappath("C:\\Documents and Settings\\user\\Desktop\\xml.docx"));
MyMailMessage.Attachments.Add(a);
}
在这里,我将内容附加到文本文件并尝试了相同的操作。所以邮件没有发送。发送包含 HTML 标签的邮件是否有任何问题。因为我能够附加一个普通的文本文件。
【问题讨论】:
-
您需要发布完整的邮件发送代码,这里没有发送部分。你怎么知道它没有发送?它会崩溃吗?
-
另外,您确定它不会因为您要发送的特定附件而被阻止吗?您是否尝试过将一个简单的字符串附加为 .txt 文件?
-
我已编辑帖子请更新。非常感谢
标签: c# .net email mailmessage