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?
 
Éric MoreauSenior .Net ConsultantCommented:
1
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CipherISAuthor Commented:
@Dustin.  I'm aware of the code you provided.  Thanks.
0
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.