Really, the only thing hard about sending email is getting things in the correct order... Here I've the send email method as an event - it would be very simple to write a wrapper around it
This event is linked to a very simple winform which you can see if you download the source code
void SendClick(object sender, EventArgs e)
MailMessage mail = new MailMessage();
It's always a good idea to say who you're email is from. Nice thing here is that if you have a wrapper around the SMTP code, you can email different people. For my example here, I just wanted to email another user account to ensure it works. When you do this sort of thing, having a second account always helps...
if (subject.Text.Length != 0)
mail.Subject = subject.Text;
mail.Subject = "I forgot to fill it in";
While there is nothing that says you must have a subject, it's a good idea to. Quite a lot of email spam blockers user a NULL in the message as a fairly high scorer on the factors when it decides if email is spam or not
mail.Body = message.Text;
If you had any attachments can be added on here. Effectively, this is the header of the email done. Now all that needs to be done is to send it
System.Net.Mail.SmtpClient smtp =
smtp.EnableSsl = true;
catch (System.Net.Mail.SmtpException ex)
"Unable to connect to the remote server",
I did say it wasn't difficult!