首页 > 解决方案 > 该文件未发送到邮件。(唯一路径)

问题描述

我有这个代码:

        epost.From = new MailAddress("test.31@gmail.com");
        epost.To.Add(textBoxMail.Text.ToString());
        epost.Subject = textBoxSubject.Text.ToString();
        epost.Body = "c:\\Users\\Raşit\\AppData\\Local\\MyText.txt"; //But i have a problem :(

        SmtpClient smpt = new SmtpClient();

        smpt.Credentials = new System.Net.NetworkCredential("test.31@gmail.com", "mypassword");
        smpt.Host = "smtp.gmail.com";
        smpt.EnableSsl = true;
        smpt.Port = 587;

        smpt.Send(epost);
        MessageBox.Show("Done!");

然后我开始调试,我看到了这个:

在此处输入图像描述

我只想要文件,我不想要路径。

标签: c#formswinforms

解决方案


System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:\\Users\\Raşit\\AppData\\Local\\MyText.txt");
epost.Attachments.Add(attachment);

推荐阅读