-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailCredentials.cs
33 lines (30 loc) · 1.07 KB
/
EmailCredentials.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Xml;
namespace DogADay
{
public class EmailCredentials
{
public void SetUpAndSendEmail(MailMessage message)
{
// smtp client set up within the using block and is disposed of once the using is done,
// which is why the Send() needs to happen here.
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
// set to false as I want to use my own credentials
smtp.UseDefaultCredentials = false;
//credentials are taken from the App.config file.
var username = ConfigurationManager.AppSettings["Username"];
var password = ConfigurationManager.AppSettings["Password"];
smtp.Credentials = new NetworkCredential(username, password);
smtp.EnableSsl = true;
smtp.Send(message);
}
}
}
}