无法与 SendGrid 集成

Hi,

I’m trying to use Sendgrid email service and keep getting this error in the logs

Job exception: 535 Authentication failed: Bad username / password

I’m not sure what I’m doing wrong, here’s how my configuration looks like

 DISCOURSE_SMTP_ADDRESS: smtp.sendgrid.net
 DISCOURSE_SMTP_PORT: 587
 DISCOURSE_SMTP_USER_NAME: apiKey
 DISCOURSE_SMTP_PASSWORD: 'SG.xxxx.xxxxxx.xxxx'

I’ve also tried to use port 2525 on the suggestion of Fresh install. Works. Sendgrid not sending emails , but that didn’t work either.

I’m able to establish a connection using telnet.

Can someone please help? Any idea what I could be doing wrong?

From the same server that your Discourse is on?

Apologies if this is a silly question but is your SendGrid username actually: apiKey

:thinking:

I only ask, as it’s an unusual choice of account name…

Yes

No, I don’t think there’s a concept of username in sendgrid, I just followed the documentation here discourse/docs/INSTALL-email.md at main · discourse/discourse · GitHub

I might be wrong also, but I don’t see any username info in my sendgrid account.

They use different terminology but you’re still connecting to what is essentially a standard SMTP server, which will require authentication.

Go to the Teammates section - https://app.sendgrid.com/settings/teammates

In there you will see the account details that are able to send email:

The value in the “Username” column is what you need to enter in the Discourse setting DISCOURSE_SMTP_USER_NAME

So if the “Username” was SK2019 then you’d have something like:

DISCOURSE_SMTP_ADDRESS: smtp.sendgrid.net
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: SK2019
DISCOURSE_SMTP_PASSWORD: 'xxxx.xxxxxx.xxxx'
3 个赞

I tried that but didn’t work. The Sendgrid docs mention to use apiKey as username, but that doesn’t seem to be working.

Maybe I should reach out to the sendgrid team and seek their help.

Did you use apiKey when using telnet?

Yes, I followed instructions at How to Send an SMTP Email | SendGrid Documentation and they worked! Not sure what am I missing in discourse configuration.

Do the four lines in your config file look like mine (above)?

With the correct DISCOURSE_SMTP_USER_NAME that matches the one displayed in your Teammates page on SendGrid?

Yes, the username is the one displayed in the the Teammates page, the password is the key I generated (telnet works using this key), and other two fields are exactly the same.

May I know what version of discourse are you using, I’m using beta, I suspect that could be the issue.

Anyways, I’m planning to switching to mailgun, I tried it today, and it works seamlessly (though it’s expensive, but have no other options atm)

2 个赞

顺便提一下 @Satwik_Kansal,我们的 Sendgrid API 用户名是 “apikey”,而不是 “apiKey”。运行良好。

遇到同样的问题。这里的要点是什么?是使用“apikey”(不起作用)还是添加团队成员(为空)?

为了记录在案,文档对此的说明相当令人困惑,这已不是我第一次为此问题搜索解决方案了。

当前文档内容为:

SendGrid — 30 天试用期内可发送 4 万封邮件

SMTP 服务器地址?smtp.sendgrid.net
SMTP 用户名?      apikey
SMTP 密码?       [SendGrid API 密钥]

编辑:我认为让人困惑的是,大家(包括我)都以为“apikey”意味着需要在这里填入你的 API 密钥,但实际上它应该保持原样!

4 个赞

真是离谱,对吧?

我猜这会让 99% 尝试过的人感到困惑 :confused:

(当时我也在其中)

1 个赞