DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

SMTP Authentication using Google Mail?

 7 Replies
 1 Subscribed to this topic
 40 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 7
New Around Here

Has anyone been able to get this to work? I've got ChatGPT to output what looked like decent instructions and have fllowed them but keep getting a "Error 400: redirect_uri_mismatch" error. I'll post the instructions below...

 

To configure OAuth for sending emails via a Google account on a DotNetNuke (DNN) 9 website, you'll need to perform the following steps, both on the DNN side and in the Google Cloud Console. This setup replaces traditional SMTP configurations, enhancing security.

Part 1: Set Up Google OAuth for Email

Step 1: Create a Google Cloud Project

  1. Log into Google Cloud Console: Go to Google Cloud Console.
  2. Create a New Project:
    • Click the project dropdown on the top navigation bar.
    • Select New Project.
    • Name the project (e.g., "DNN Email OAuth"), and click Create.
  3. Enable Gmail API:
    • In your project dashboard, click on APIs & ServicesLibrary.
    • Search for Gmail API and click on it.
    • Click Enable.

Step 2: Create OAuth 2.0 Credentials

  1. Create OAuth Credentials:

    • In the API & Services section, navigate to Credentials.
    • Click Create CredentialsOAuth 2.0 Client IDs.
    • Select Web application for the application type.
    • Add a name (e.g., "DNN OAuth Email").
    • Under Authorized redirect URIs, add a dummy URI (e.g., <code><a href="https://your-dnn-site.com/oauth2/callback" target="_blank" rel="nofollow">https://your-dnn-site.com/oauth2/callback</a></code>).
    • Click Create.
  2. Get OAuth Credentials:

    • Once created, you'll receive a Client ID and Client Secret. Save these as you will need them for your DNN configuration.

Step 3: Set Up OAuth Consent Screen

  1. Configure OAuth Consent Screen:
    • Go to OAuth consent screen under APIs & Services.
    • Set the user type to External.
    • Fill out the required fields such as the application name (e.g., "DNN Email OAuth") and add your website domain.
    • Add your email address and the required information under the Authorized domains section.

Step 4: Authorize Scopes for Gmail API

  1. Set Up OAuth Scopes:
    • Under APIs & ServicesOAuth Consent Screen, add the Gmail API scope.
    • Add the following scope for Gmail API: <code><a href="https://www.googleapis.com/auth/gmail.send" target="_blank" rel="nofollow">https://www.googleapis.com/auth/gmail.send</a></code>.

Part 2: Configure DotNetNuke to Use OAuth for Google Email

Step 1: Access SMTP Settings in DNN

  1. Log into DNN as an administrator or superuser.
  2. Navigate to SettingsServers.
  3. Click on SMTP Server Settings.

Step 2: Input OAuth Settings

  1. Configure SMTP:
    • SMTP Mode: Select OAuth2.
    • SMTP Server: Use <code>smtp.gmail.com</code>.
    • SMTP Port: Use port <code>587</code> for TLS or <code>465</code> for SSL.
    • SMTP Authentication: Set it to OAuth2.
  2. Client ID & Secret:
    • Enter the Client ID and Client Secret obtained from Google Cloud.
  3. Authorization Endpoint:
    • Use the authorization URL: <code><a href="https://accounts.google.com/o/oauth2/auth" target="_blank" rel="nofollow">https://accounts.google.com/o/oauth2/auth</a></code>.
  4. Token Endpoint:
    • Use the token URL: <code><a href="https://oauth2.googleapis.com/token" target="_blank" rel="nofollow">https://oauth2.googleapis.com/token</a></code>.
  5. Redirect URI:
    • Set this to the URI used in your Google Cloud setup (e.g., <code><a href="https://your-dnn-site.com/oauth2/callback" target="_blank" rel="nofollow">https://your-dnn-site.com/oauth2/callback</a></code>).

Step 3: Test the Configuration

  1. Save your settings and click Test SMTP Settings to ensure that everything is correctly configured.
  2. If successful, DNN will now use Gmail via OAuth for sending emails.
New Around Here
Posts: 7
New Around Here

For anyone having a similar problem, I was able to figure out the issue. I don't see it documented anywhere, but this is the redirect_uri you need to setup from your Google Cloud Authorized Redirect URIs field for your Credential. If for some reason it's different, you can check the web browser console network tab to see the redirect_uri field filled out after you tap the Authorize button in DNN.

https://www.[yoursite...eMail/Authorize.aspx

Senior Member
Posts: 1325
Senior Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
Lifesaver
Lifesaver
You're Life Saver!
New Poster
New Poster
Congrats on posting!
3 Engaged Reader
Engaged Reader
You are an engaged reader!
Posted By PeteyBlah on 10/3/2024 6:24 PM

For anyone having a similar problem, I was able to figure out the issue. I don't see it documented anywhere, but this is the redirect_uri you need to setup from your Google Cloud Authorized Redirect URIs field for your Credential. If for some reason it's different, you can check the web browser console network tab to see the redirect_uri field filled out after you tap the Authorize button in DNN.

https://www.[yoursite...eMail/Authorize.aspx

Ah, right, that's the same for Exchange.
Thank you for posting the solution, very helpful for future users. :-)

 

 

New Around Here
Posts: 7
New Around Here

Just to follow up, it appears it's still authenticating with the original SMTP email address I had.

The 'X-Google-Original-From' header in the email is showing the original email address.

Has anyone had that happen before, or know how to fix it? Or even debug it?

New Around Here
Posts: 7
New Around Here
Also, where is the "from name" being set? I can't find it anywhere in the settings and the emails (new registration, password reset, etc) still have the original from name being set?
New Around Here
Posts: 7
New Around Here
I changed a superuser Display name, and that seems to have changed the from email display name, is that really the place it's pulling that from? Why? I see in instructions in various places, that there used to be placed to change the from email name, but I don't see that anywhere in the settings anymore. Is it also pulling that email address from the super user email address? Is there some legacy setting enabled after updating from dnn7 that is causing this? Anyone have any ideas? Thanks.
Senior Member
Posts: 1325
Senior Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
Lifesaver
Lifesaver
You're Life Saver!
New Poster
New Poster
Congrats on posting!
3 Engaged Reader
Engaged Reader
You are an engaged reader!
Posted By PeteyBlah on 10/9/2024 3:44 PM
I changed a superuser Display name, and that seems to have changed the from email display name, is that really the place it's pulling that from? Why? I see in instructions in various places, that there used to be placed to change the from email name, but I don't see that anywhere in the settings anymore. Is it also pulling that email address from the super user email address? Is there some legacy setting enabled after updating from dnn7 that is causing this? Anyone have any ideas? Thanks.

The email used comes from the HostSettings Table and AFAIK there is not edit interface for that and some other settings related to the main Host in the Persona Bar:

HostEmail            
HostPortalId            
HostTitle            
HostURL            

 

 

New Around Here
Posts: 7
New Around Here

I have those host settings saved in my host settings table.

My registration and other emails still list the (X-Google-Original-From) header as coming from my superuser email.

And the "from name" is set from that superuser as well, even though those host settings are set.

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved