Reputation: 9043
I created an html using string builder and placed it in the current directory
StreamWriter sw = new StreamWriter("../../Data.html");
Now I want to attach this file and send it as a mail. How can I add this as an attachment to my email?
This is what I do more or less with a regular html message. How can I add the file as an attachment to it?
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;
Upvotes: 0
Views: 111
Reputation: 23675
Attachment attachment = new Attachment(attachmentPath);
msg.Attachments.Add(attachment);
Upvotes: 1
Reputation: 3717
Here's a CodeProject article that goes over adding an attachment to a MailMessage
. I'd consider taking a look at that first, and returning with any questions presented.
http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
Here's some MSDN reading as well: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments.aspx
Upvotes: 1
Reputation: 4039
Here you go, http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
The above answer was just a google away.
Upvotes: 2