how to send mail via using

Posted on 2009-12-20
Last Modified: 2013-11-26
hello i want to know how could i send mail via using
.. i want to send in gmail address...

also know if some users register in my webapplication then how could i send the welcome mail with well formatted .. kindly send me the code .. i am very thankful..

    LVL 9

    Expert Comment

    by:Grant Spiteri
    LVL 11

    Accepted Solution

    here's the code to send email (make sure you provide your smtp information correctly, I assumed in my example that you would use a gmail accoun to send your emails):
                //create the mail message
                MailMessage mail = new MailMessage();

                //set the addresses
                mail.From = new MailAddress("");

                //set the content
                mail.Subject = "This is an email";
                mail.IsBodyHtml = true;
                mail.Body = "<b>this is a sample bold body</b>";

                //set smtpClient
                SmtpClient smtpClient = new SmtpClient("", 587);
                smtpClient.EnableSsl = true;
                smtpClient.Credentials = new NetworkCredential("", "password");
                //send the message
    LVL 13

    Assisted Solution

    using System;
    using System.Web.Mail;
    namespace WebMail
        class Class1
            static void Main(string[] args)
                    MailMessage oMsg = new MailMessage();
                    // TODO: Replace with sender e-mail address.
                    oMsg.From = "";
                    // TODO: Replace with recipient e-mail address.
                    oMsg.To = "";
                    oMsg.Subject = "Send Using Web Mail";
                    // SEND IN HTML FORMAT (comment this line to send plain text).
                    oMsg.BodyFormat = MailFormat.Html;
                    // HTML Body (remove HTML tags for plain text).
                    oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
                    // ADD AN ATTACHMENT.
                    // TODO: Replace with path to attachment.
                    String sFile = @"C:\temp\Hello.txt";  
                    MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
                    // TODO: Replace with the name of your remote SMTP server.
                    SmtpMail.SmtpServer = "MySMTPServer";
                    oMsg = null;
                    oAttch = null;
                catch (Exception e)
                    Console.WriteLine("{0} Exception caught.", e);

    LVL 29

    Expert Comment

    by:Kumaraswamy R

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now