C# 用C语言发送带有附件的邮件#

C# 用C语言发送带有附件的邮件#,c#,.net,email,mailmessage,C#,.net,Email,Mailmessage,我需要发送一封邮件,包括作为附件的异常详细信息(死亡的黄色屏幕) 我可以得到如下的YSOD: string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage(); if (!string.IsNullOrEmpty(YSODmarkup)) { Attachment YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.htm"); mm.Attachment

我需要发送一封邮件,包括作为附件的异常详细信息(死亡的黄色屏幕)

我可以得到如下的YSOD:

string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
if (!string.IsNullOrEmpty(YSODmarkup))
{
    Attachment YSOD = Attachment.CreateAttachmentFromString(YSODmarkup, "YSOD.htm");
    mm.Attachments.Add(YSOD);
}
mm
属于
MailMessage
类型,但邮件未发送

这里

用于绑定邮件正文

在此之后,仅添加附件。 删除附件时,会发送邮件

有人能帮我吗


根据Albin先生和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标签的邮件有什么问题吗。因为我可以附加一个普通的文本文件

您需要发布完整的邮件发送代码,此处没有发送部分。你怎么知道它没有被发送?它会崩溃吗?另外,您确定它不会因为您试图发送的特定附件而被阻止吗?你有没有试过把一个简单的字符串附加为.txt文件?我已经编辑了帖子,请更新。非常感谢:message.Attachments.Add(Attachment.CreateAttachmentFromString(“MyContent”,“test.txt”);
namespace SendAttachmentMail
{
    class Program
    {
        static void Main(string[] args)
        {
            var myAddress = new MailAddress("jhered@yahoo.com","James Peckham");
            MailMessage message = new MailMessage(myAddress, myAddress);
            message.Body = "Hello";
            message.Attachments.Add(new Attachment(@"Test.txt"));
            var client = new YahooMailClient();
            client.Send(message);
        }
    }
    public class YahooMailClient : SmtpClient
    {
        public YahooMailClient()
            : base("smtp.mail.yahoo.com", 25)
        {
            Credentials = new YahooCredentials();
        }
    }
    public class YahooCredentials : ICredentialsByHost
    {
        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            return new NetworkCredential("jhered@yahoo.com", "mypwd");
        }
    }
}
namespace SendAttachmentMail
{
    class Program
    {
        static void Main(string[] args)
        {
            var myAddress = new MailAddress("jhered@yahoo.com","James Peckham");
            MailMessage message = new MailMessage(myAddress, myAddress);
            message.Body = "Hello";
            message.Attachments.Add(new Attachment(@"Test.txt"));
            var client = new YahooMailClient();
            client.Send(message);
        }
    }
    public class YahooMailClient : SmtpClient
    {
        public YahooMailClient()
            : base("smtp.mail.yahoo.com", 25)
        {
            Credentials = new YahooCredentials();
        }
    }
    public class YahooCredentials : ICredentialsByHost
    {
        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            return new NetworkCredential("jhered@yahoo.com", "mypwd");
        }
    }
}