Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7405257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:22:36+00:00 2026-05-29T05:22:36+00:00

How can i send my html email content as an attachment of any format.

  • 0

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;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:22:37+00:00Added an answer on May 29, 2026 at 5:22 am

    Try something like this

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net.Mail;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            MailMessage mail = new MailMessage();
            mail.To.Add(txtTo.Text);
            mail.From = new MailAddress(txtFrom.Text);
            mail.Subject = txtSubject.Text;
            mail.Body = txtMessage.Text;
            mail.IsBodyHtml = true;
    
            //Attach file using FileUpload Control and put the file in memory stream
            if (FileUpload1.HasFile)
            {
                mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
            }
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential
                 ("email@domain.com", "YourGmailPassword");
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
    
        }
    }
    

    If you want to add stream of your data to MailMessage try this

    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
    writer.Write("Hello its my sample file");
    writer.Flush();
    writer.Dispose();
    
    System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain);
    System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, ct);
    attach.ContentDisposition.FileName = "myFile.txt";
    
    // I guess you know how to send email with an attachment
    // after sending email
    ms.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to send HTML content in email using Python? I can send simple texts.
I have to send an email having all content in html that can be
How can I send an HTML-formatted email with pictures using PHP? I want to
I have several sites where users can send me email through an html form
I know that soap can send XML over http, is there any way to
How can i send an Email using PHP at windows Azure? i am using
I want to send HTML content via email. I open gmail via intent and
I want to send html email.I am using spring framework Mailsender class to send
I'm using PEAR to send HTML emails from my website. My email are sent,
I'm attempting to include a zip attachment with some html content in an email

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.