ASP.NET - how to send - Asked By Bala Marish on 20-May-11 04:18 AM

how to send html greetings to email using me some good links and some flows.
dipa ahuja replied to Bala Marish on 20-May-11 04:25 AM
protected void btnSent1_Click(object sender, EventArgs e)
    string toEmailAddress = "";
    string GmailId = "";
    string password = "";
    string bodyMsg = "<html><body><img src=''/></body></html>";
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(GmailId);
    mail.Subject = txtSubject.Text;
    mail.Body = bodyMsg;
    mail.IsBodyHtml = true;
    //OR attatch from your computer
    if (FileUpload1.HasFile)
      mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
    SmtpClient smtp = new SmtpClient("");
    smtp.EnableSsl = true;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
Jem Savery replied to Bala Marish on 20-May-11 04:29 AM

Hi Marish, see the following code, 

protected void yourButton_Click(object sender, EventArgs e)
        string strMailContent = "Welcome new user";
        string fromAddress = "";
        string toAddress = "";
        string contentId  = "image1";
        string path = Server.MapPath(@"images/Logo.jpg"); // my logo is placed in images folder
        MailMessage mailMessage = new MailMessage( fromAddress, toAddress );
        mailMessage.Bcc.Add(""); // put your id here
        mailMessage.Subject = "Welcome new User";

        LinkedResource logo = new LinkedResource(path);
        logo.ContentId = "companylogo";
   // done HTML formatting in the next line to display my logo
        AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:companylogo/><br></body></html>" + strMailContent, null, MediaTypeNames.Text.Html);

        mailMessage.IsBodyHtml = true;
        SmtpClient mailSender = new SmtpClient("localhost"); //use this if you are in the development server

 Note:SmtpClient mailSender = new SmtpClient(ConfigurationManager.AppSettings["MyCustomId"]); // use this in the Production Server. I have specified my email server in the web.config file

Ref :

Hope this helps.

Mahendar Nanamala replied to Bala Marish on 20-May-11 04:39 AM

You have asked some links refer below link:


    public void SendMail()
        MailMessage msgMail = new MailMessage();
        msgMail.To =TextBox1.Text;
        msgMail.From = "HR IN";
        msgMail.Subject = "Regarding Enquiry";
        System.Net.Mail.Attachment attachment;
                msgMail.BodyFormat = MailFormat.Html;
        string strBody = "<html><body><b>Hi" + TextBox2.Text.ToUpper() + "</b></br><br/>" +
           " <font color=\"red\">Greetings from Interactive Head!</font><br/><br/>We got your query.
 We will get back to you soon.<br/>" +
           "Thanks and Regards<br/>Interactive Head<br>NH-24 Shanti Nagar<br/>Near Kamla Hall,<br/>
 Ghaziabad<br>Uttar Pradesh , India <br/>Contact no.: +91 97-170-09112</body></html>";
        msgMail.Body = strBody;
        SmtpMail.SmtpServer = "";
        msgMail.Fields.Add("", "1");
// your Email id
        msgMail.Fields.Add("", "");
// Your password
        msgMail.Fields.Add("", "9897851861");
        msgMail.Fields.Add("", "465");
        msgMail.Fields.Add("", "true");


protected void Button1_Click(object sender, EventArgs e)