How can i send my html email content as an attachment of any format.
I am using a FAX API, that allows me to send an attachment with respective Fax Number.
And the API will Fax that Attachment to the Fax Number provided.
here is my code
public string SendFax(int ID)
{
MailMessage message = new MailMessage();
//To address
message.To.Add(new MailAddress("email@domain.com"));
message.Subject = "My Subject";
//Specify true if it is html message
message.IsBodyHtml = true;
Class Details = new Class();
Details = Details.GetDetails(ID);
string mailBody = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Documents/EmailTemplates/FaxTemplate.htm"));
//Prescriber details.
mailBody = mailBody.Replace("%FirstName%", Details.FirstName);
mailBody = mailBody.Replace("%LastName%", Details.LastName);
mailBody = mailBody.Replace("%OfficeName%", Details.PracticeName);
mailBody = mailBody.Replace("%AddressLIne1%", Details.AddressLine1);
mailBody = mailBody.Replace("%Phone%", Details.Phone);
mailBody = mailBody.Replace("%FaxNumber%", Details.Fax);
mailBody = mailBody.Replace("%DEANumber%", Details.DEANUmber);
message.Body = mailBody;
status = Send(message);
if (status.Equals(string.Empty))
status = "Failure sending Fax" + "|" + "0";
else
status = "Successfully Faxed";
return status;
}
public string Send(MailMessage message)
{
string host = WebConfigurationManager.AppSettings["SMTPHost"].ToString();
int port = Convert.ToInt32(WebConfigurationManager.AppSettings["SMTPPort"]);
string username = WebConfigurationManager.AppSettings["SMTPUsername"].ToString();
string password = WebConfigurationManager.AppSettings["SMTPPwd"].ToString();
string fromAddress = WebConfigurationManager.AppSettings["EmailFrom"].ToString();
SmtpClient smtpC = new SmtpClient();
smtpC.Host = host;
smtpC.Port = port;
//smtpC.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpC.Credentials = new System.Net.NetworkCredential(username, password);
smtpC.EnableSsl = false;
message.From = new MailAddress(fromAddress);
smtpC.Send(message);
status = "Success";
return status;
}
Try something like this
If you want to add stream of your data to MailMessage try this