?
Solved

how to send mail via asp.net using C#.net

Posted on 2009-12-20
4
Medium Priority
?
467 Views
Last Modified: 2013-11-26
hello i want to know how could i send mail via asp.net using C#.net
.. 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..

Thanks..
0
Comment
Question by:AVARICESOFT
4 Comments
 
LVL 9

Expert Comment

by:Grant Spiteri
ID: 26092495
0
 
LVL 11

Accepted Solution

by:
lenordiste earned 1000 total points
ID: 26092508
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("me@gmail.com");
            mail.To.Add("someone@gmail.com");

            //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("smtp.gmail.com", 587);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new NetworkCredential("me@gmail.com", "password");
            //send the message
            smtpClient.Send(mail);
0
 
LVL 13

Assisted Solution

by:Ashok
Ashok earned 1000 total points
ID: 26092515
using System;
using System.Web.Mail;
 
namespace WebMail
{
    class Class1
    {
        static void Main(string[] args)
        {
            try
            {
                MailMessage oMsg = new MailMessage();
                // TODO: Replace with sender e-mail address.
                oMsg.From = "sender@somewhere.com";
                // TODO: Replace with recipient e-mail address.
                oMsg.To = "recipient@somewhere.com";
                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);
 
                oMsg.Attachments.Add(oAttch);
 
                // TODO: Replace with the name of your remote SMTP server.
                SmtpMail.SmtpServer = "MySMTPServer";
                SmtpMail.Send(oMsg);
 
                oMsg = null;
                oAttch = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }
    }
}

HTH
Ashok
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 26093084
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

864 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