我使用字符串构建器创建了一个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;
答案 0 :(得分:2)
你走了, http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
上面的回答只是一个谷歌。
答案 1 :(得分:1)
这是一篇关于向MailMessage
添加附件的CodeProject文章。我考虑首先考虑一下,然后回答任何问题。
http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
以下是一些MSDN阅读:http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments.aspx
答案 2 :(得分:1)
Attachment attachment = new Attachment(attachmentPath);
msg.Attachments.Add(attachment);