Sendgrid API and Two Factor Authentication

BillyS

Well-Known Member
Mar 22, 2013
62
4
58
cPanel Access Level
Root Administrator
I use google compute engine and use SendGrid to handle email. Exim configuration has worked for ages, then I noticed I could not send emails. For a day I was confused (it happens), then I realized SendGrid is pushing Two Factor Authentication (which I did) so this part of my exim configuration (below) was no longer working. Sure enough when I turned off 2 factor, I could send emails again.

begin authenticators

sendgrid_login:
driver = plaintext
public_name = LOGIN
client_send = : YourSendGridUsername : YourSendGridPassword

So being a good admin, I created a Sendgrid API Key. The problem I am having is there are no clear instructions in terms of how to use exim4 and the SendGrid API Key. I tried creating an environment variable for the key (using export), then using:

client_send = : YourSendGridUsername : MY_SENDGRID_ENV_VARIABLE

But that didnt work.

So I tried

client_send = : YourSendGridUsername : TheActualKeyItself

That didnt work. When I go to the mail queue, and try to deliver the mail, I can see that authentication is failing. What am I missing?
 

BillyS

Well-Known Member
Mar 22, 2013
62
4
58
cPanel Access Level
Root Administrator
Some additional trial and error, finally got this one. If this is wrong please let me know, but it does work.

sendgrid_login:
driver = plaintext
public_name = LOGIN
client_send = : apikey : TheActualKeyItself

What's interesting is I found a post elsewhere that said substitute your userID for apikey (which is what I tried), I also tried using the ApiKeyID, which didnt work either. Just simply "apikey" as the user did the trick. The only question I do have is around security of this approach. I also noticed "export" was not permanent as an environmental variable - which I found is normal after much reading.
 

cPanelJohn

Moderator
Staff member
Sep 29, 2020
12
2
78
Hawaii
cPanel Access Level
Root Administrator
Hello,

Some additional trial and error, finally got this one. If this is wrong please let me know, but it does work.

sendgrid_login:
driver = plaintext
public_name = LOGIN
client_send = : apikey : TheActualKeyItself

I'm glad you were able to get this working. We suggest the same configuration here:

How to use SendGrid as a Smarthost

You may also find this helpful for more information on setting up SendGrid as a smarthost.