using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
/// <summary>
/// Summary description for SendTheMail
/// </summary>
public class SendTheMail
{
public static bool SendMail(string
ToAddress, string subject, string body)
{
try
{
string OutGoingSMTP = "SMTP-Outgoing
Address";
string FromAddress = "Sender
Email";
string FromPassword = "Email
Password";
string
FromDisplayName = "Name Of Sender";
int OutgoingSMTPPort = PortNo; /// example: 26
var fromAddress = new
MailAddress(FromAddress, FromDisplayName);
var toAddress = new MailAddress(ToAddress);
var smtp = new SmtpClient
{
Host = OutGoingSMTP,
Port = OutgoingSMTPPort,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address,
FromPassword)
};
using (var message = new MailMessage(fromAddress,
toAddress)
{
IsBodyHtml = true,
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
return true;
}
catch (Exception
ae)
{
return false;
}
}
}
No comments:
Post a Comment