question

AJEETSINGH-4016 avatar image
0 Votes"
AJEETSINGH-4016 asked Ben-Miller-DBAduck answered

SQL Database Mail configuration with sendgrid

I have been trying to setup sendgrid on SQL Database Mail but all the time it says Cannot send mail to mail server.

This is what i have done.

I have sendgrid accound with abc@mydomain.com and created api key and SG.xxxx password.
As this is prod setup instance, i had done domain level authentication and my webmaster updated CNAME as requested by sendgrid.
Tested using TELNET smtp.sendgrid.net 587 and authenticated with SG.xxxx password Base64 encoded and this was able to send email from abc@mydomain.com to xyz@mydomain.com
I setup profile with abc@mydomoain.com as SQL notification Profile and selected Basic Authentication and provided 'apikey' as username and 'SG.xxx' as password in Database Mail - 'Configure Database Mail' option in SQL SSMS. Unchecked - 'The server requires secure authentication (SSL) connection' Port 587
I tried to 'Send Test Mail' with 'abc@domain.com' to 'xyz@mydomain.com' but the Database Mail reflects as below screenshot error
I have tried using abc@mydomain.com and sendgrid account password in Database Mail Config wizard for Basic authentication, but sendgrid suggested they don't accept Basic authentication. Please help how and where should i pass the api key if not under Basic Authentication ?
I tried updating with msdb.dbo.sysmail_add_account_sp nad updating records but it too didn't resolve and send email from Database mail.

Any help/ guidance would be greatly appreciated or if you had faced this how have you resolved it.

135484-image.png


sql-server-general
image.png (8.6 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AJEETSINGH-4016,

We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.

Best regards,
Seeya

0 Votes 0 ·

Hi Seeya,
The resolution provided didn't helped.

Regards

0 Votes 0 ·
StratosMatzouranis avatar image
0 Votes"
StratosMatzouranis answered AJEETSINGH-4016 commented

Have you tried to click "This server required a secure connection (SSL)" ?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, i tried both with/without ssl.

An additional information that's missing above:

Under Basic authentication I am using username as base64 encode of string "apikey" and password also base64 encoded of "SG.xxx"
I encoded this using below on linux terminal openssl

echo -n '<YOUR_API_KEY>' | openssl base64

Will this affect anything on Database Mail configuration ?
Should i use some other base64 encode method. Although, by using cmd - telnet with this encoded key I was able to authentication and send email.

0 Votes 0 ·
SeeyaXi-msft avatar image
0 Votes"
SeeyaXi-msft answered

Hi @AJEETSINGH-4016,

Could you refer to this troubleshooting first: https://houseofbrick.com/troubleshooting-database-mail-for-sql-server/
Maybe it is hopeful for you.
If it doesn't work please feel free to let me know.

Best regards,
Seeya


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ben-Miller-DBAduck avatar image
0 Votes"
Ben-Miller-DBAduck answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.