You can use SendGrid if you want to send emails to outside of your O365 tenant. They have a free plan if the emails are limited to 100 per day.
You will find code examples in their GitHub repository. Following is one example to send emails using their API through C#.
// using SendGrid's C# Library
// From: https://sendgrid.com/docs/for-developers/sending-email/v3-csharp-code-example/
internal class Example
private static void Main()
static async Task Execute()
var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
var client = new SendGridClient(apiKey);
var from = new EmailAddress("firstname.lastname@example.org", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("email@example.com", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);