How To send an email Using C#

How To send an email Using C#

                                                                                                                                                           

in this c# tutorial we will see how to to Send An Email With C# .


Project Source Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace email
{
    public partial class Form1 : Form
    {
     
        public Form1()
        {
            InitializeComponent();
        }

        private void send_Click(object sender, EventArgs e)
        {
            MailMessage msg = new MailMessage("your gmail                       mail",textTo.Text,textSubject.Text,textmail.Text);
            msg.IsBodyHtml = true;
            SmtpClient sc = new SmtpClient("smtp.gmail.com",587);
            sc.UseDefaultCredentials = false;
            NetworkCredential cre = new NetworkCredential("your gmail mail",textpass.Text);//your mail password
            sc.Credentials = cre;
            sc.EnableSsl = true;
            sc.Send(msg);
            MessageBox.Show("Mail Send");
        }

    }
}

//////////////////////////////  END


Share this

Related Posts

Previous
Next Post »

1 comments:

comments
31 octobre 2015 à 06:58 delete

service not available, closing trasmission channel. the server response was: cannot connect to SMTP server, either for 587 port or 465 one.
ime getting this error, could u suggest a solution please

Reply
avatar