SMTP Username overwrites mailMessage.Sender and fails with Azure SendGrid

Description

TLDR Description:
If your SMTP server settings requires a username and that username has an "@" symbol in it, the mailMessage.Sender field may be overwritten with the SMTP Username setting.

Description:
We migrated our website to Azure recently and configured our email to use the SendGrid azure implementation. By default, when signing up for SendGrid through Azure, your username is in the form of 'azure_[numbers]@azure.com'. This is used for the SMTP authentication when sending emails. We also configured SendGrid with WhiteLabels so that emails sent from our website will properly show to customers instead of getting the annoying "Sent on behalf of" From name.

We then configured our host account to the name 'noreply@[domain].com'. Generally, we use this email form when configuring a site as we don't want people replying to messages automatically sent from the system. When we call any of the methods of DotNetNuke.Services.Mail.Mail.SendMail(...), and manually specifying an email address of 'noreply@[domain].com', all our messages are not WhiteLabeled and the headers are incorrect for the sender (see dnn_BadHeaders.png – the header on the left is bad, the right is good). The right is good because we were sending from webmaster@ instead of the usual noreply.

I decompiled the DotnetNuke.Services.Mail information to see how the SendMailInternal function handled my sender fields and if there was a work around I could use. And I found the code explicitly overwrites the sender information with the SMTP username in a certain condition. See dnn_SendMailInternal.png.

This should be updated so that you can have SMTP usernames with @ signs in them as that is the default for Azure SendGrid implementations.

QA Test Plan

None

Attachments

2

Activity

Show:

Details

Assignee

Reporter

Story Size

Severity

Triage

Includes Code Fix

No

Components

Affects versions

Priority

Created May 16, 2017 at 9:05 PM
Updated May 30, 2017 at 6:03 PM