Sending the Emails With Authentication

Suresh.mekkattil
Posted by Suresh.mekkattil under ASP.NET category on | Points: 40 | Views : 1749
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace EmailTester
{
class Program
{
static void Main(string[] args)
{
SendEmail();
}
private static void SendEmail()
{
try
{
System.Net.Mail.MailMessage message = new MailMessage();

message.From = new MailAddress("from");
message.To.Add(new MailAddress("to"));
message.Subject = "Sub:";
message.IsBodyHtml = true;
message.Body = "body";

SmtpClient emailClient = new SmtpClient("mail.domain.com");
System.Net.NetworkCredential SMTPUserInfo = new NetworkCredential("username", "Pass");
emailClient.UseDefaultCredentials = false;
emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

// Set this to true when your mail server is enabled the SSL.
emailClient.EnableSsl = false;

emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);

}
catch (Exception ex)
{

}
}
}
}

Comments or Responses

Login to post response