using System.Data;
using System.Configuration;
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.Text;
using System.Net.Mail;
using System.Collections.Generic;
///
/// Summary description for MailSender
///
public class MailSender
{
public MailSender(string body,string subj)
{
this.Body = body;
this.Subject = subj;
}
public MailSender()
{
}
string _body, _subject;
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
public string Body
{
get { return _body; }
set { _body = value; }
}
public void SendMail(string toAddress)
{
if (toAddress != null && toAddress != string.Empty)
{
MailMessage objmessage = new MailMessage();
objmessage.Priority = MailPriority.High;
objmessage.Subject = Subject;
objmessage.Body = Body;
objmessage.IsBodyHtml = true;
objmessage.From = new MailAddress(Convert.ToString(ConfigurationManager.AppSettings["emailid"]));
objmessage.To.Add(new MailAddress(toAddress));
try
{
SmtpClient objsmtpClient = new SmtpClient();
objsmtpClient.Host = ConfigurationManager.AppSettings["mailserver"].ToString();
objsmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objsmtpClient.Send(objmessage);
}
catch (SmtpException mailex)
{
throw mailex;
}
}
}
public void SendMail(List
{
if (addrCollection.Count >0)
{
MailMessage objmessage = new MailMessage();
objmessage.Priority = MailPriority.High;
objmessage.Subject = Subject;
objmessage.Body = Body;
objmessage.IsBodyHtml = true;
objmessage.From = new MailAddress(Convert.ToString(ConfigurationManager.AppSettings["emailid"]));
foreach (string item in addrCollection)
{
objmessage.To.Add(new MailAddress(item));
}
try
{
SmtpClient objsmtpClient = new SmtpClient();
objsmtpClient.Host = ConfigurationManager.AppSettings["mailserver"].ToString();
objsmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objsmtpClient.Send(objmessage);
}
catch (SmtpException mailex)
{
throw mailex;
}
}
}
public void SendMail(string fromAddress,string toAddress)
{
if (toAddress != null && toAddress != string.Empty)
{
MailMessage objmessage = new MailMessage();
objmessage.Priority = MailPriority.High;
objmessage.Subject = Subject;
objmessage.Body = Body;
objmessage.IsBodyHtml = true;
objmessage.From = new MailAddress(fromAddress);
objmessage.To.Add(new MailAddress(toAddress));
try
{
SmtpClient objsmtpClient = new SmtpClient();
objsmtpClient.Host = ConfigurationManager.AppSettings["mailserver"].ToString();
objsmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objsmtpClient.Send(objmessage);
}
catch (SmtpException mailex)
{
throw mailex;
}
}
}
}
No comments:
Post a Comment