Send Email With Gmail SMTP server Setting in ASP.NET
Here i used parameterized function like i passed all the values of the mail through the parameter values
public void  funSendEmail(string txtToAdd, string txtCCAdd, string txtFromAdd, string txtSubject, string txtEmailBody)
    {
        MailMessage message = new MailMessage();
        message.To.Add(new MailAddress(txtToAdd));
        message.CC.Add(new MailAddress(txtCCAdd));
        message.From = new MailAddress(txtFromAdd);
        string NetworkPassword = "you mail account password"; //Network password is you mail account password
        message.Subject = txtSubject;
        message.Body = txtEmailBody;
        message.IsBodyHtml = true;
        message.Priority = MailPriority.High;
        message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
        SmtpClient smtp = new SmtpClient();
        smtp.Credentials = new System.Net.NetworkCredential(txtFromAdd, NetworkPassword);
        smtp.Port = 587; // Gmail works on this port
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
       
        
       
        smtp.Send(message);
       
    }
 
 
No comments:
Post a Comment