Using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Mail;
namespace Baselib
{
public class SendMail
{
public void Sendtxtmail (string from, String, string to, string subject, mailpriority priority, string body, String smtpserver, System.Collections.ArrayList files)
{
mailmessage msg = new MailMessage ();
Msg. from = from;
Msg. to = to;
Msg. Subject = Subject;
Msg. Priority = Priority;
Msg. BodyFormat = Mailformat.text;
Msg. BODY = body;
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Basic Authentication
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername", from. Substring (0, from. IndexOf ("@")); Set your username here
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword", pass); Set your password here
for (int i = 0; i < files. Count; i++)
{
if (System.IO.File.Exists (files[i). ToString ())
{
Msg. Attachments.Add (New MailAttachment (files[i). ToString ()));
}
}
smtpmail.smtpserver = SmtpServer;
Try
{
smtpmail.send (msg);
}
catch (Exception ex)
{
}
}
public void Sendhtmlmail (string from, String, string to, string subject, mailpriority priority, string body, string s Mtpserver, System.Collections.ArrayList files)
{
mailmessage msg = new MailMessage ();
Msg. from = from;
Msg. to = to;
Msg. Subject = Subject;
Msg. Priority = Priority;
Msg. BodyFormat = mailformat.html;
Msg. BODY = body;
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Basic Authentication
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername", from. Substring (0, from. IndexOf ("@")); Set your username here
Msg. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword", pass); Set your password here
for (int i = 0; i < files. Count; i++)
{
if (System.IO.File.Exists (files[i). ToString ())
{
Msg. Attachments.Add (New MailAttachment (files[i). ToString ()));
}
}
smtpmail.smtpserver = SmtpServer;
smtpmail.send (msg);
}
}
}