C# Send SMTP

I am writing code to send an email via SMTP.  Which design pattern should be used to implement.  High level example would be nice.

Thanks
LVL 2
CipherISAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
You can use System.Net.Mail

https://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx

Quick example:
MailMessage mail = new MailMessage("your@email.com", "them@email.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "Hello";
mail.Body = "Hello there.  See you at lunch.";
client.Send(mail);

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
This is not what I have in mind when seeing "design patterns" in a question!
0
CipherISAuthor Commented:
@Dustin.  I'm aware of the code you provided.  Thanks.
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

CipherISAuthor Commented:
@Eric - and what did you have in mind?  I am looking for a Design Pattern to use to send emails.  I am looking for recommendations.
0
Éric MoreauSenior .Net ConsultantCommented:
I don't know any design patterns related to sending emails. I all I wanted to say is that a snippet of code that has nothing special can surely not be considered a "design pattern"
0
Éric MoreauSenior .Net ConsultantCommented:
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
Currently the app I'm working on uses SMTP and POP3.  I can write code to process SMTP but that would require separate code for the POP3.

Strategy Pattern?  Chain of Responsibility?
0
Éric MoreauSenior .Net ConsultantCommented:
I would opt for the chain of responsibility as shown in https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern
2
CipherISAuthor Commented:
Exactly what I was looking for.  Thanks.
0
Dustin SaundersDirector of OperationsCommented:
This is not what I have in mind when seeing "design patterns" in a question!

You're right Eric, apologies as I misread the question.  Happens sometimes when I run through a handful of code questions in a row.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.