Click here to Skip to main content
15,896,392 members
Articles / Web Development / ASP.NET

Email Providers (SMTP/GMail) using Provider Design Pattern

Rate me:
Please Sign up or sign in to vote.
4.56/5 (7 votes)
27 Dec 2013CPOL2 min read 18.6K   328   29  
Configure different email provider sources using the Provider design pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Provider.EmailSender;

namespace EmailTesting
{
    public partial class EmailSend : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            SendEmail();
        }

        private void SendEmail()
        {
            EmailInfo emailInfo = new EmailInfo();
            emailInfo.To = txtTo.Text.Trim();
            emailInfo.From = txtFrom.Text.Trim();
            emailInfo.Subject = txtSubject.Text;
            emailInfo.Body = txtBody.Text;

            //Create object of manager class and call sendEmail method which will do rest of things.
            EmailProviderManager obj = new EmailProviderManager();
            obj.InitializeProvider();

            obj.MyEmailProvider.SendEmail(emailInfo);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions