我使用字符串生成器创建了一个 html 并将其放在当前目录中
StreamWriter sw = new StreamWriter("../../Data.html");
现在我想附上这个文件并作为邮件发送。如何将此作为附件添加到我的电子邮件中?
这或多或少是我对常规 html 消息所做的。如何将文件添加为附件?
public bool sendMailAttachment(string to, string from, string subject, string body, string attachment)
{
bool k = false;
try
{
SmtpClient client;
MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
client = new SmtpClient();
client.Host = "staging.itmaniax.co.za";
//client.Port = 25;
//****
//client.EnableSsl = true;
client.Send(msg);
k = true;
}
catch (Exception exe)
{
Console.WriteLine(exe.ToString());
}
return k;