How to send mail to another email id through gmail provider using c#.net



C# Code:

MailMessage Msg = new MailMessage();
            // Sender e-mail address.
            string FromMail = "noreplysofttechsolving@gmail.com";
            string Password = "xxxxxx"; //sender email password
            Msg.From = new MailAddress(FromMail);
            // Recipient e-mail address..
            string ToMail = txtEmail.Text;
            Msg.To.Add(ToMail);
            string MsgBody = "Thank you!!!!";
            AlternateView htmlMsgView = AlternateView.CreateAlternateViewFromString(MsgBody, null, MediaTypeNames.Text.Html);
            Msg.Subject = "SoftTechSolving";
            //Msg.Body = MsgBody;
            Msg.AlternateViews.Add(htmlMsgView);
            // your remote SMTP server IP.
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential(FromMail, Password);
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            Msg = null;


Namespace:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Net.Mail;

using System.Net.Mime;

Popular posts from this blog

How to protect your Drive/Flash USB Drive (Pen Drive) with Password without using any software