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 666465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:49:18+00:00 2026-05-13T23:49:18+00:00

I’ve found this small code that sends email to gmail users. I’d like the

  • 0

I’ve found this small code that sends email to gmail users. I’d like the body of the mail to contain html (for example, decoding a link for it to hold different text than the url it’s pointing to).

I am using c# .net 3.5. I’ve used these classes in my code:

  • MailMessage
  • SmtpClient

How can this be done?

Here’s a copy of my code:

            MailMessage message = new MailMessage("me@gmail.com", WebCommon.UserEmail, "Test", context.Server.HtmlEncode("<html> <body> <a href='www.cnn.com'> test </a> </body> </html> "));
            System.Net.NetworkCredential cred = new System.Net.NetworkCredential("him@gmail.com", "myPwd");
            message.IsBodyHtml = true;

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");

            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            smtp.Credentials = cred;
            smtp.Port = 587;

            smtp.Send(message);

Thanks!

  • 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-13T23:49:19+00:00Added an answer on May 13, 2026 at 11:49 pm

    Something like this should work:

    Note that MailMessage refers to System.Net.MailMessage. There is also System.Web.MailMessage, which I have never used and -as far as I know- is obsolete.

    MailMessage message = new MailMessage();
    // Very basic html. HTML should always be valid, otherwise you go to spam
    message.Body = "<html><body><p>test</p></body></html>"; 
    // QuotedPrintable encoding is the default, but will often lead to trouble, 
    // so you should set something meaningful here. Could also be ASCII or some ISO
    message.BodyEncoding = Encoding.UTF8;
    message.IsBodyHtml = true;
    // No Subject usually goes to spam, too
    message.Subject = "Some Subject";
    // Note that you can add multiple recipients, bcc, cc rec., etc. Using the 
    // address-only syntax, i.e. w/o a readable name saves you from some issues
    message.To.Add("someone@gmail.com");
    
    // SmtpHost, -Port, -User, -Password must be a valid account you can use to 
    // send messages. Note that it is very often required that the account you
    // use also has the specified sender address associated! 
    // If you configure the Smtp yourself, you can change that of course
    SmtpClient client = new SmtpClient(SmtpHost, SmtpPort) {
                Credentials = new NetworkCredential(SmtpUser, SmtpPassword),
                EnableSsl = enableSsl;
            };
    
            try {
                // It might be necessary to enforce a specific sender address, see above
                if (!string.IsNullOrEmpty(ForceSenderAddress)) {
                    message.From = new MailAddress(ForceSenderAddress);
                }
                client.Send(message);
            }
            catch (Exception ex) {
                return false;
            }
    

    For more sophisticated templating solutions that render the Body html rather than hard-codin it, there is, for example, the EMailTemplateService in MvcContrib which you can use as a guideline.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer assuming that the html content is already in a php… May 14, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer There isn't a Truncate() method on string, unfortunately. You have… May 14, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer I thought I should come back to this with what… May 14, 2026 at 8:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.