c# - 该文件未发送到邮件。(唯一路径)
问题描述
我有这个代码:
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!");
然后我开始调试,我看到了这个:
我只想要文件,我不想要路径。
解决方案
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:\\Users\\Raşit\\AppData\\Local\\MyText.txt");
epost.Attachments.Add(attachment);
推荐阅读
- keystore - JavaWS 不以 Signed Jars 开头,表现得像 unsigned
- vue.js - 安装时启动函数的组合 API 问题。没有数据
- python - 在 Windows 10 上的 R Studio 中安装和运行 Tensorflow 的噩梦
- database - 不知道我应该使用哪个数据库
- flutter - 如何使用 flutter_typeahead 和 FirestoreFirebase 生成建议?
- parameters - CloudFormation - 根据另一个参数的值过滤允许值的列表
- java - 通过作为另一个实体的实体属性的 id 更新
- ckeditor - 无法在移动设备上播放 ckeditor html5 音频中的音频文件
- inno-setup - Inno Setup 的重命名和更改语言“需要至少 X MB 的可用磁盘空间”页面
- python - 如何将 .gsheet 文件作为文本文件读取?