我需要發送包含異常詳細信息(黃色屏幕死亡)的郵件作爲附件。用C#發送郵件附件郵件
我能得到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());
用於將郵件主體結合。
之後只添加附件。 刪除附件時,會發送郵件。
任何人都可以幫我嗎?
按照從阿爾文先生和Paul先生的評論正在更新以下
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標籤的郵件是否有問題?因爲我能夠附加一個正常的文本文件。
你需要發佈完整的郵件發送代碼,你沒有發送部分在這裏。你怎麼知道它沒有發送?它會崩潰嗎? – 2011-02-27 11:06:12
另外,您是否確定它不會因爲您要發送的特定附件而被阻止?你有沒有嘗試過將一個普通的字符串作爲一個.txt文件? – 2011-02-27 14:54:05
我已編輯帖子請更新。非常感謝 – Anjana 2011-02-27 20:50:06