Monday, March 19, 2012

Send Email C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
namespace TyroDeveloperDLL
{
    public class clsMail
    {
        string userid = "";
        public String UserId {
            get { return userid; }
            set { userid = value; }
        }
        string userpassword = "";
        public String UserPassword {
            get { return userpassword; }
            set { userpassword = value; }
        }
        string host = "";
        public String  Host {
            get { return host; }
            set { host = value; }
        }
        int port = 80;
        public Int32 Port{
            get { return port; }
            set { port = value; }
        }
        string destination_email = "";
        public String DestinationEmail {
            get { return destination_email; }
            set { destination_email = value; }
        }
        string subject = "";
        public String Subject {
            get { return subject; }
            set { subject = value; }
        }
        string message = "";
        public String Message {
            get { return message; }
            set { message = value; }
        }
        MailPriority priority = MailPriority.Normal;
        public MailPriority EmailPriority {
            get { return priority; }
            set { priority = value; }
        }
        public bool Send(string prmDestinationEMail, string prmSubject, string prmMessage)
        {
            try
            {               
                MailMessage correo = new MailMessage();
                correo.From = new MailAddress(userid);
                correo.To.Add(prmDestinationEMail);
                correo.Subject = prmSubject;
                correo.Body = prmMessage;
                correo.IsBodyHtml = true;
                correo.Priority = priority;
                SmtpClient smtp = new SmtpClient();
                smtp.Credentials = 
                    new System.Net.NetworkCredential(userid, userpassword);
                smtp.Host = host;
                smtp.Port = port;
                smtp.EnableSsl = true;
                smtp.Send(correo);
                return (true);

            }
            catch (Exception ex)
            {
                throw(ex);
            }
        }
        public bool Send()
        {
            try
            {
                MailMessage correo = new MailMessage();
                correo.From = new MailAddress(userid);
                correo.To.Add(destination_email);
                correo.Subject = subject;
                correo.Body = message;
                correo.IsBodyHtml = true;
                correo.Priority = priority;
                SmtpClient smtp = new SmtpClient();
                smtp.Credentials = 
                    new System.Net.NetworkCredential(userid, userpassword);
                smtp.Host = host;
                smtp.Port = port;
                smtp.EnableSsl = true;
                smtp.Send(correo);
                return (true);

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}

Please visit: www.TyroDeveloper.com

Please Click on +1

No comments:

Post a Comment