how to send a email please explain step by step

Recommended Answers

All 7 Replies

Welcome,

To send an email, you may use the Mail API - System.Net.Mail namespace classes - especially SmtpClient, MailMessage and MailAddress.

I suggest you to read the forum rules (Member rules) before you post anything.

How to send email by using c# please exaplain me a example

The links supplied include code samples.

commented: valid post in reply to poster reluctant to show willing +4

ya k tinstaafi i am the new one to dot net plat form , i dont know exactly what is what thats why i am asking again clearly

  1. Get Email Address From User
  2. Get Subject From User
  3. Get Message From User
  4. Get Destination Address From User
  5. Connect to SMTP Server
  6. Send Mail
  7. ?????
  8. Profit

ya k tinstaafi i am the new one to dot net plat form , i dont know exactly what is what thats why i am asking again clearly

If you don't read the links, which have far more extensive information than a post here would contain, what makes you think that someone posting the code here will help any more?

Anyway, consider the following and see if it helps. It's basically the bare minimum for sending an email through SMTP:

using System;
using System.Net;
using System.Net.Mail;

public class Program
{
    public static void Main()
    {
        try
        {
            SendEmail(
                "smtp.live.com",          // Hotmail's SMTP server
                "foodiddles@hotmail.com", // Note: Bogus login information
                "imapassword",
                true,                     // SSL required for Hotmail
                "foodiddles@hotmail.com", // Bogus sender
                "foo@bar.com",            // Bogus recipient
                "Test Email",
                "This is a test email.");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

    public static void SendEmail(
        string server, string userName, string password, bool useSSL, // Server info
        string sender, string recipient, string subject, string body, // Message info
        int timeout = 30)
    {
        using (var mail = new MailMessage())
        {
            var smtp = new SmtpClient(server);

            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(userName, password);
            smtp.EnableSsl = useSSL;
            smtp.Timeout = 1000 * timeout;

            mail.From = new MailAddress(sender);
            mail.To.Add(new MailAddress(recipient));
            mail.Subject = subject;
            mail.Body = body;

            smtp.Send(mail);
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.