Envio de E-mail com ASP.NET

Criei uma class que envia e-mail com .net



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//Chama os objetos responsável por enviar e-mail
using System.Web.Mail;

namespace sgdc._appclass
{
    public class Email
    {
        private string _mensagem;

        public string Mensagem
        {
            get { return _mensagem; }
            set { _mensagem = value; }
        }
        private string _from;

        public string From
        {
            get { return _from; }
            set { _from = value; }
        }
        private string _to;

        public string To
        {
            get { return _to; }
            set { _to = value; }
        }
        private string _assunto;

        public string Assunto
        {
            get { return _assunto; }
            set { _assunto = value; }
        }
        private string _formatoCorpo;

        public string FormatoCorpo
        {
            get { return _formatoCorpo; }
            set { _formatoCorpo = value; }
        }
        private string _body;

        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }
        private string _smtpServer;

        public string SmtpServer
        {
            get { return _smtpServer; }
            set { _smtpServer = value; }
        }
        private string _send;

        public string Send
        {
            get { return _send; }
            set { _send = value; }
        }

//Metodo responsável por enviar e-mail
        public void Enviar(string from, string to, string assunto, string texto)
        {
            this._from = from;
            this._to = to;
            this._assunto = assunto;
            this._body = texto;
            MailMessage email = new MailMessage();
            try
            {

                MailMessage mail = new MailMessage();
                mail.To = to;
                mail.From = from;
                mail.Subject = assunto;
                mail.Body = texto;
                SmtpMail.SmtpServer = "localhost";  //your real server goes here
                SmtpMail.Send(mail);
            }
            catch (Exception ex)
            {
                this._mensagem = "Ocorreram problemas no envio do e-mail. Erro = " + ex.Message;
            }
            finally
            {
             
            }

        }


    }
}

Nenhum comentário:

Postar um comentário