Office 365 SMTP: Setup and Configuration Explained
Tags: webdev, smtp, beginners, tutorial
Published: 2024-05-01 17:35:18

In this guide, I dive deep into the ins and outs of Office 365, showing you what it’s best used for and how to configure it, while also providing you with some actual examples.

## What is an Office 365 SMTP server?
SMTP, or Simple Mail Transfer Protocol, is an internet standard protocol responsible for delivering messages to the email server and relaying emails between senders and recipients. 

Thus, Office 365 is an SMTP service from Microsoft.

However, in 2020, Office 365 was renamed to Microsoft 365.

Microsoft 365 is a subscription-based service, which includes Office 365 SMTP. So, when you refer to the Office 365 SMTP, you refer to the Microsoft 365 SMTP.

However, we’ll be using Office 365 to keep things simple.

### Office  365 SMTP vs. Outlook SMTP
Office 365 SMTP is often confused with Outlook SMTP on the internet, but don’t mix up the two, because Office 365 is subscription-based, whereas Outlook is free.

Here are some differences between the two:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kpe8okwfojegu6a5gnu.png)

## Why should you use Office 365 as a SMTP server?
Some of the most common Office 365 SMTP use cases include:

- Sending transactional emails – Password resets and order confirmations are some of the transactional emails you can send through Office 365 SMTP. 
- Integration with custom applications – You can use Office 365 to add email-sending functionality to custom applications and send your users updates, reminders, or other emails specific to your app.
- Scheduling and event reminders – If you’re operating within the Microsoft 365 ecosystem, you can use Office 365 SMTP to send event reminders, schedule appointments, and more.
- Automatic notifications from IoT devices – Besides the standard notifications, you can also leverage Office 365 SMTP to send notifications or alerts from Internet of Things (IoT) devices through email. For example, you can set up your monitoring system to use Office 365 SMTP to notify you when there’s an anomaly. 
- Sending emails from different clients with an Office 365 address – Whether you prefer using Thunderbird or Yahoo Mail clients, you can send emails through Office 365 from them. 
- Sending emails for small-scale marketing efforts – Although it’s not the most optimal solution for bulk email campaigns as you’ll see later in the article, Office 365 can be used for marketing campaigns with low volume but highly targeted needs.

## How to configure Office 365 SMTP server settings?
According to Microsoft’s official documentation, there are three options for configuring Office 365 SMTP server settings. Namely:

- SMTP AUTH client submission – Lets you email anyone both inside or outside an organization and it supports OAuth 2.0, offering a more secure authentication method. Most importantly, it’s easy to configure, making it an ideal choice for sending emails from your application or email client.
- Direct send – Doesn’t let you send emails to external recipients and your messages will be subject to Microsoft’s spam filters. Moreover, emails you send via this option don’t get saved in the Sent Items folder, which can be a big drawback.
- SMTP relay – Setting up an SMTP relay in Office 365 is the most complex of the three options as it requires configuring a connector in Office 365 and managing static IP addresses or certificates. Like Direct send, SMTP relay also doesn’t support modern authentication methods like OAuth.

As you can see, especially if you’re a developer looking to add email-sending functionality to your application, SMTP AUTH client submission more or less takes the cake. 🎂

Now, let me show you how to configure it.

#### Step 1. Verify and enable SMTP AUTH 
First things first, we need to enable SMTP AUTH on your mailbox to send emails through Office 365 SMTP.

To check if SMTP AUTH is enabled, you can use:

**Exchange Admin Center (EAC)**

Log in to the EAC with your admin account.
Navigate to “Recipients” → “Mailboxes”
Find and select your mailbox.
Check the status of your SMTP AUTH

**PowerShell**

Connect to Exchange Online PowerShell using your admin credentials.
You can also use ‘Connect-ExchangeOnline’ cmdlet
Run the following command to check the SMTP AUTH of your mailbox:
`Get-CASMailbox -Identity "user@domain.com" | Format-List SmtpClientAuthenticationDisabled`

If ‘SmtpClientAuthenticationDisabled’ is ‘False’, SMTP AUTH is enabled
If ‘SmtpClientAuthenticationDisabled’ is ‘True’, SMTP AUTH is disabled
Run the following command to enable SMTP AUTH for your mailbox:

`Set-CASMailbox -Identity "user@domain.com" -SmtpClientAuthenticationDisabled $false`

**Notes:**

Any changes you make either through EAC or PowerShell probably won’t take effect immediately, so you might need to wait a while.
Verifying and enabling SMTP AUTH requires administrative access to your Office 365 account.

#### Step 2. Insert the necessary Office 365 SMTP settings
To send emails via Office 365 SMTP, enter the following settings into your app or email client:

SMTP server name: smtp.office365.com
SMTP port: Port 587 (recommended) or port 25
TLS/StartTLS: Enabled
Username/email address: john.doe@yourcompanyname.com
Password: Your Office 365 password
Note: If you have MFA enabled, you’ll need to generate an app password to log in.

## Configuration examples
Now that you’re familiar with Office 365 SMTP and know how to configure it, let’s see some actionable examples in WordPress, PHP, and Thunderbird.

### WordPress Office 365 SMTP settings
If you’re a WordPress user, you can configure the Office 365 SMTP with plugins like WP Mail SMTP or Post SMTP for instance.

All you have to do is:

Sign in to your WordPress account
Install a plugin (I used WP Mail SMTP in this example)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3hc4yqswb9nxeth8c19.png)

Navigate to WP Mail SMTP → Settings
Choose ‘Other SMTP’ as the mailer
Enter the Office 365 settings

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/753ra1pdqimmwjzba579.png)

### PHP
When it comes to PHP, you have several email-sending libraries to choose from. In this example, I’ll use Symfony because of its practicality.

Here’s a code snippet you can modify with your Office 365 credentials to send emails:

```
<?php

use Symfony\Component\Mailer\Mailer; 
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport; 
use Symfony\Component\Mime\Email;

require_once './vendor/autoload.php';


$transport = (new Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
('smtp.server.com', 587))
                ->setUsername('username')
                ->setPassword('password');

$mailer = new Mailer($transport); 

$email = (new Email())
            ->from('hello@registered.com')
            ->to('you@example.com')
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')
            ->html('<p>See Twig integration for better HTML integration!</p>');

$mailer->send($email);
```

### Thunderbird
As I’ve previously mentioned, besides custom applications, you can also set up email clients like Thunderbird to send emails through Office 365 SMTP.

Here’s how you can do it:

Open the Thunderbird email client
Click on ‘Account Settings’ in the upper-right corner of the window


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw9tldbzmunawocn3p9u.png)

Select ‘Outgoing Server (SMTP)’ at the bottom of the drop-down menu


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycszepaasmddtpgs6x0t.png)

Enter your Office 365 settings


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8grndouf0jmf053tr1qu.png)

Keep in mind that I’ve used Thunderbird version 115.0 in this example, so there might be differences in your access to ‘Account Settings’ if you’re using an older version of the client.

## How to configure Office 365 POP3 settings?
Once you’ve configured your Office 365 SMTP, you’ll need an ”email retrieval” or “pull protocol” for fetching messages from the server. One of such protocols is Post Office Protocol 3, or POP3 for friends.

POP3 lets you download messages from your Office 365 account to your local device. It can be useful if you have a limited connection and want to view your messages offline or if you want to create a backup of emails by storing them locally.

### Office 365 POP3 settings
To use Office POP3, insert these settings into your app configuration or email client:

Server name: outlook.office365.com
Port: 995
TLS/StartTLS: Enabled
Username/email address: john.doe@yourcompanyname.com
Password: Your Office 365 password

## How to configure Office 365 IMAP settings?
Another pull protocol you can use to retrieve your emails is IMAP or Internet Message Access Protocol.

IMAP is considered by many a more convenient protocol than POP3 as it synchronizes your emails across your devices. It stores them on the email server, where you can manage, open, view, and delete your messages. In essence, IMAP works similarly to cloud email.

### Office 365 IMAP settings
To use Office 365 IMAP, you’ll need the following settings:

Server name: smtp.office365.com
Port: 993
TLS/StartTLS: Enabled
Username/email address: john.doe@yourcompanyname.com
Password: Your Office 365 password

## POP3 vs IMAP – which one is better?
Simply put, POP3 and IMAP serve different purposes and fit different personal needs, so we can’t really say one is better than the other.

However, most users nowadays could benefit more from IMAP as we use different devices to fetch our emails. And as mobile networks have become more affordable and Wi-Fi is everywhere, the synchronization IMAP offers can really go a long way.

Moreover, IMAP is the default protocol for the majority of modern email clients.

But, whether you want to store your emails on your local devices for security reasons or for convenience’s sake, POP3 is the way to go for you.

## Troubleshooting Microsoft Office 365 SMTP server configuration
I’ve scoured the community forums for the most common Microsoft Office 365 errors so you don’t have to, and here are some of the most common ones:

**System.Net.Sockets.SocketException (0x80004005)**
This error message means that you either don’t meet SMTP AUTH requirements or your network firewall or Internet Service Provider (IDP) are blocking ports 587 or 25.

In case you meet the requirements, here’s how you can check if you’re potentially getting blocked:

Open Command Prompt (CMD) as an administrator
Type ‘telnet’ to run telnet
Run the following command:
open smtp.office365.com 587(25)
If you’re able to successfully connect, you will receive a response line similar to:

220 BY1PR10CA0041.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 1 Jun 2024 12:00:00 +0000
In case you can’t connect, try disabling your firewall or contacting your ISP.

**SMTP send error. The operation has timed out**
Although a common error, this error is likely caused either by your antivirus software or firewall blocking your SMTP connection or a typo in your Office 365 settings. If neither of these solutions works, then the issue is probably on Microsoft’s end, in which case you’ll need to contact their support.

**5.7.60 SMTP; Client does not have permissions to send as this sender.**
If you’re seeing this error, check whether your application or email client is trying to send emails from a different address than the one you’ve entered in your SMTP configuration. The two need to be the same for the sending to work.

But, you can also give the ‘Send As’ permission to another address if you plan to use two different addresses for email sending.

**Transport Layer Security (TLS) encryption related errors**
Recently, Microsoft has started rejecting connections to smtp.office365.com that use TLS1.0/1.1 for SMTP AUTH. So, make sure your device supports TLS version 1.2 or above.

But, if you need to use older versions of TLS for legacy clients and devices, you can:

Go to Settings in your Exchange admin center
Navigate to Mail Flow (under Security)
Check “Turn on use of legacy TLS clients)
Click “Save”
For more information on Office 365 and TLS, read the official Microsoft’s article.

## Office 365 SMTP limitations or when not to use Microsoft 
Office as an SMTP server
While Office 365 does offer a reliable SMTP server, it has some considerable limitations that you should go over before deciding on it as your go-to option.

Namely, they include:

- Monthly subscription fees – To have access to Office 365 SMTP server, you’ll need to pay a monthly subscription. It has several pricing plans, with the basic one starting at  $6.99 per month and allowing you to send emails to up to 10,000 recipients per day.

It’s important to note that 10,000 recipients per day is not the same as sending 10,000 emails per day. 

- No support for bulk email sending – Office 365 SMTP is not the most ideal option for sending large amounts of emails as the sending limit is the same for all pricing tiers. This means that even if you pay for Enterprise E3/E5 (the most expensive plan), you will still be limited to 10,000 recipients per day and 30 messages per minute, which can be a considerable issue.

If you’re looking for a bulk-sending alternative, here’s an in-depth article on the top 10 mass email service providers.

- Lack of monitoring features – Typically, most SMTP service providers offer in-depth analytics and reporting features, which can help you optimize your campaign and improve your email deliverability. Unfortunately, this isn’t the case with Office 365.

- Steep learning curve – Getting the hang of Office 365 can be quite a challenge as it’s not the most user-friendly SMTP service out there. Add to this the wide range of features and services offered by the whole suite, and you’ll realize why most new users may even need training to navigate Office 365 complexities.

## Consider an alternative — using Mailtrap Email Sending
If you’re like me and Office 365 SMTP limitations are too much for you, don’t worry—I have just the right solution.

I use Mailtrap, an Email Delivery Platform for developer teams to test, send, and control their email infrastructure in one place. 

Personally, I needed to send bulk mail, so I used Mailtrap’s Bulk Stream to send large amounts of marketing and promotional emails in my high-volume campaigns to enhance my deliverability even further.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lpwhizje5ix3azuy3q6.png)

Additionally, I use Mailtrap’s detailed analytics to check my bounce rates, open rates, click-through rates and other useful stats. This allows me to keep track of my email infrastructure and optimize it accordingly.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4l9jt7mxagq9i09ar2u1.png)

Mailtrap Email Sending also provides me with deliverability alerts every Monday to let me know how my emails are doing in the form of in-depth stats and I also get hourly alerts when a critical metric goes below a predetermined threshold.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpoy3yoxuyt8797n6nwm.png)

As enhancing my deliverability goes, I make sure to test my emails before sending them out, a part of the email-sending process that goes with it like salt goes with pepper. 🧂

Without testing my emails, I risk having them being marked as spam, or, worst case scenario: their HTML template getting poorly rendered by certain web browsers.

Mailtrap Email Testing, a part of the Mailtrap Email Delivery Platform lets me check my spam score, inspect and verify my HTML/CSS and make sure it’s pitch-perfect before it reaches my recipients’ inboxes.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gw3euh5kdlaqbnqrtfeo.jpg)

Lastly, and perhaps most importantly, Mailtrap is super easy to use.

Check it out:

Register an account on Mailtrap.
Add and verify your domain under ‘Sending Domains’


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mo4hd72w6b4u5u5nydj1.png)

Navigate to the ‘SMTP/API Settings’ tab and choose your preferred SMTP stream.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y2wcg3ohs3vpabz4391.png)

Use the SMTP settings provided by Mailtrap to integrate the functionality within your custom application or email client.
Make sure everything is configured and works correctly by sending a test email.

We appreciate the you chose this article to find out how to set up Office 365. If you want to find more interesting content on related topics, follow [Mailtrap blog](https://mailtrap.io/blog/office-365-smtp/)!