punkouter
punkouter

Reputation: 5366

Should I use the GRAPH API or a simple SMTP class to create an email ?

I don't seem to get it. I can create some code to send an email like this:

  String userName = "[email protected]";
String password = "your password";
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("ToAddress"));
msg.From = new MailAddress(userName);
msg.Subject = "Test Office 365 Account";
msg.Body = "Testing email using Office 365 account.";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.office365.com";
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.Port = 587; 
client.EnableSsl = true;
client.Send(msg);

Or I can create an app in our Azure AD and set the permissions and send an email with the GRAPH API right?

Is there any possible reason I would want to use the GRAPH API to do this ?

Upvotes: 0

Views: 4177

Answers (2)

Harini Vedala
Harini Vedala

Reputation: 399

In addition to what others have mentioned here about OAUTH, if you need to track/see the Sent email inside the sending user's Outlook "Sent" messages folder, you have to use Graph API. If you use SMTP, the sent message will not show up in the "Sent" messages folder. You might need that for some audit/tracking reasons. If you don't care about that, then SMTP is just fine.

Upvotes: 0

Jason Johnston
Jason Johnston

Reputation: 17702

Well you're asking for an opinion, so it's hard to give an all-inclusive answer. However, one reason that you might prefer Graph over SMTP is that it uses OAuth, so you do not need to ask for or store the user's username or password.

Upvotes: 2

Related Questions