استكشاف مشكلة البريد الإلكتروني على تثبيت Discourse جديد

You just installed Discourse via the install guide, but email doesn’t seem to work. Unfortunately this means you can’t log in as an admin to finalize the install. :cry: Let’s troubleshootize!

Try the doctor :woman_health_worker:

If you run ./discourse-doctor it will check several ways that your mail configuration might be broken, and offer advice. Try that first.

Did you enter email settings correctly?

The simplest way is to run ./discourse-setup again. Did you enter everything correctly? But wait! If your password has anything other than numbers and letters, you might be better off editing your app.yml with nano or your favorite editor.

You can also double check the settings in your containers/app.yml file. A valid email section looks like this:

DISCOURSE_DEVELOPER_EMAILS: 'name@example.com'
DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: postmaster@discourse.example.com
DISCOURSE_SMTP_PASSWORD: aUd34cdWKCu6CTjfoH7ykk

Closely examine all values for correctness. Note that:

  • it all aligns
  • no leading # characters
  • single quotes around the developer email field
  • password does not include ", ', %, ] or other special characters

If you had any errors in your app.yml and made changes, you MUST rebuild the container for those changes to take effect!

cd /var/discourse/
./launcher rebuild app

Well, you don’t always need to rebuild

Doing a rebuild will often fix things that seem broken, but it takes a while. There are times when a full rebuild is not necessary; the above is usually the best advice, but If you change just SMTP settings, you can do just this to apply them without doing a full rebuild:

cd /var/discourse
./launcher destroy app
./launcher start app

Are your SMTP connections being blocked?

To confirm that your server can indeed contact the email server, issue this command:

telnet smtp.mailgun.org 587

If you can’t connect this way, you’re almost certainly blocked. (And if you do get connected, the escape character for SMTP is ctrl+], then use quit to exit telnet.)

If this happens, first try port 2525, and if that fails, contact your cloud provider support and confirm that your email connections are not being blocked.

What do the Discourse logs say?

From the command line, issue this command:

cd /var/discourse
tail shared/standalone/log/rails/production.log

This will show the last few lines of the log. Look for anything mail related. If you need to view the fuller logs, try

less shared/standalone/log/rails/production.log

To page through the complete log, press space or type GG to jump to the end. Look closely for any email related messages or press /, type email, and hit enter to search.

What do your email provider logs say?

Assuming there are no errors in the Discourse logs, or your Discourse mail configuration, the emails probably went out. The question, is what did your email provider do with them?

Most email providers have a log viewing function. Check the logs for your email domain and see what happened with the incoming emails.

Did you properly set up DKIM and SPF records for your domain?

You must enter those crucial DNS records for DKIM and SPF, otherwise your emails may arrive only sporadically, if at all.

Is the email domain correct?

The default email from address is based on the install domain plus subdomain, so if your URL is discourse.example.com it will be:

noreply@discourse.example.com

But if your mail provider is expecting:

noreply@example.com

… you may have problems! To get around this, edit and uncomment this exec line in app.yml

## If you want to set the 'From' email address for your first registration, uncomment and change:
#- exec: rails r "SiteSetting.notification_email='noreply@example.com'"
## After getting the first signup email, re-comment the line. It only needs to run once.

You’ll need to issue a rebuild after uncommenting the above line and setting the from email address as required.

You can also change this from the command line, if needed:

./launcher enter app
rails r "SiteSetting.notification_email = 'discourse@yoursite.com'"
exit

If using Mailgun – have you activated your domain and provided credit card info?

If you are using Mailgun, after you enter your DKIM and SPF records, you must visit https://mailgun.com/app/domains/YOUR.DISCOURSE.DOMAIN.com and click the “Check DNS Records Now” button. At the top of that page you should see “State ACTIVE” (in a calming green). If it says “State Unverified” (in a scary warning-yellow) Mailgun will not accept mail.

Mailgun now requires a credit card in order to deliver mail (other than to you). If your mailgun logs have a message about “free accounts,” this is your problem.

Other mail services have similar requirements.

Are you using an IP address as the mail domain?

This does not work in our experience. You must use a domain name when sending email, not an IP address like 192.168.1.1.

If you really want to go on with an IP address, try mail settings similar to these:

DISCOURSE_SMTP_ADDRESS: 172.17.0.1         # e.g. use internal docker IP here
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: "YOUR-SMTP-USER-NAME"
DISCOURSE_SMTP_PASSWORD: "YOUR-SMTP-PASSWORD"
DISCOURSE_SMTP_ENABLE_START_TLS: true     # (optional, default true)
DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
DISCOURSE_SMTP_DOMAIN: example.com

Need to log in without receiving a registration email?

We don’t recommend this, because your email is still broken, and you have a broken Discourse until email is working. But if you absolutely must log in as admin with email broken, here’s what to do:

cd /var/discourse
./launcher enter app
rake admin:create

And answer the prompts. It takes a few seconds before they appear. When it asks for the password, you will not be able to see what you type. That is why it makes you type it twice.

Email smtp port selection (Using 465?)

The ability to be able to AUTH using ‘telnet’ is extremely important in your first steps of email troubleshooting.

Port 465 (SMTP over SSL) is largely deprecated in favor of STARTTLS on 25. You may need to try alternate ports such as port 2525 or port 587 (Mail Submission) when things do not seem to work as expected.

Command Line SMTP tests for experienced sysadmins

If you’re comfortable with the command line, these might help diagnose network or certificate problems. If these do not seem “easy-to-follow” then you should please ignore this section.

See also Test SMTP Authentication and StartTLS - Sysadmins of the North.

Office 365 Tweaks

If you’re using Office 365, be sure to include these (the first line is what you are likely missing):

DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: true
DISCOURSE_SMTP_PORT: 587

and set the correct value for DISCOURSE_SMTP_NOTIFICATION_EMAIL (which is likely different from your forum hostname).

TLS and SSL issues

By default, Discourse uses STARTTLS to encrypt its connection to the email server. Some email servers (increasingly rare nowadays) don’t support this or aren’t configured to use it, so it can be disabled by adding this line:

DISCOURSE_SMTP_ENABLE_START_TLS: false    #default: true

Other email servers might support STARTTLS, but use a self-signed certificate. This is uncommon and can be enabled with:

DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none #default: peer

Email still doesn’t work! What next?

Anything else I forgot here? Feel free to edit this.


Debug issues with first connection to smtp server from inside the Discourse container

1. Enter your container:

./launcher enter app

2. Check dns resolving for your smtp server name via getent hosts:

(dig, nslookup, ping etc. are not installed inside the container.)

getent hosts your.smtp.server

On success, it will look like this or will be blank on failure.

# IPv4
123.123.123.123 your.smtp.server

# IPv6
2001:db8:0:0:0:ff00:42:8329 your.smtp.server

3. Try to open a connection to your smtp server via openssl:

(telnet, nc etc. are not installed inside the container.)

Fiddle with some different settings until you succeed with a connection.

openssl s_client -connect your.smtp.server:465
openssl s_client -connect your.smtp.server:587 -starttls smtp

# IPv4
openssl s_client -connect 172.17.0.123:465
openssl s_client -connect 172.17.0.123:587 -starttls smtp

# IPv6
openssl s_client -6 -connect "[2001:db8:0:0:0:ff00:42:8329]:465"
openssl s_client -6 -connect "[2001:db8:0:0:0:ff00:42:8329]:587" -starttls smtp

See: How to check SMTP connection → Step 3: Checking SMTP Connection Over TLS Using Openssl

4. Use your found working connection settings with Discourse.

:rocket:

Bonus: show Discourse IP from inside docker container

( ifconfig , ip etc. are not installed inside the container.)

hostname -I

Result like:

172.17.0.2

Last edited by @grayphilo 2025-03-04T18:51:41Z

Check documentPerform check on document:
57 إعجابًا

هل هذه معلومات محدثة؟ لم تنجح معي؛ اضطررت إلى إعادة بناء التطبيق بعد تغيير منفذ SMTP.

إعجابَين (2)

إذا أخبرك discourse-doctor أن الاتصال بالمنفذ 587 فشل، ولكن openssl s_client -connect your.smtp.server:587 -starttls smtp يعمل بشكل جيد، فجرب هذا، يجب أن يستغرق كلا الأمرين نفس القدر من الوقت:

time openssl s_client -starttls smtp -connect your.smtp.server:587 </dev/null > /dev/null

docker run --rm discourse/base:2.0.20231023-1945 bash -c 'time openssl s_client -starttls smtp -connect your.smtp.server:587 </dev/null' > /dev/null

إذا كان إصدار docker أطول بكثير، فقد يكون لديك تكوين خاطئ في ملف /etc/docker/daemon.json. قد تحاول وضع خادم أسماء Google في المقام الأول:

{
  "dns": ["8.8.8.8", "ww.xx.yy.zz", "ww.xx.yy.za"]
}

يعمل المنفذ 2525 لـ Mailjet.
فشل المنفذ 587.

إعجابَين (2)

لقد قمت بتحرير المنشور الأصلي لاقتراح استخدام المنفذ 2525. خدمة الاستضافة الخاصة بك هي التي تحظر المنفذ. بسبب ذلك، تدعم العديد من خدمات البريد أيضًا 2525.

3 إعجابات

مرحباً، أردت فقط إضافة ملاحظة حول هذا الأمر؛

يتطلب Mailgun الآن بطاقة ائتمان لتسليم البريد (بخلاف البريد إليك). إذا كانت سجلات Mailgun الخاصة بك تحتوي على رسالة حول “الحسابات المجانية”، فهذه هي مشكلتك.

لقد قمت بالتسجيل هذا الأسبوع (يوليو 2024) وحتى الآن، يعمل بدون الحاجة إلى إضافة بطاقة ائتمان، باستخدام المستوى المجاني الأساسي. بناءً على ما رأيته في خيوط المنتديات القديمة، يبدو أنهم كانوا يتقلبون بشأن هذه السياسة، واستخدامات وقيود المستويات المجانية الخاصة بهم، ربما.

إعجاب واحد (1)

واو. هذا جنوني ومختلف تمامًا عن كيفية سير الأمور طالما أتذكر.

لقد كان من الصعب جدًا على الأشخاص معرفة كيفية التغيير إلى خطة الدفع حسب الاستخدام وعدم الاشتراك في خطة شهرية باهظة الثمن إلى حد ما.

هل أرسلت إلى مستخدمين آخرين غير نفسك؟

إعجاب واحد (1)

نعم، لقد أرسلت إلى المستخدمين، وهو يعمل. العقبة الوحيدة هي أن عناوين البريد الإلكتروني الخاصة بـ AOL تحظر رسائلي لسبب ما، ولكن لا أعتقد أن هذا خطأ MailGun. أنا مندهش مثلك :slight_smile:

تحديث: يبدو أن سبب حظر بعض رسائل البريد الإلكتروني هو أن عنوان IP المستخدم لإرسال رسائل البريد الإلكتروني المجانية من MailGun مشترك، لذلك تم الإبلاغ عنه على أنه “بريد عشوائي” بواسطة بعض منصات البريد الإلكتروني مثل AOL و Yahoo Mail وغيرها. يبدو أن كل من لا يستخدم Gmail يواجه رفضًا أو عدم تسليم للبريد الإلكتروني.

إعجاب واحد (1)

هل يمكنك من فضلك شرح كيفية التحقق من الإعدادات في ملف containers/app.yml الخاص بنا؟ نحن المبتدئون لا نعرف كيف نفعل هذه الأشياء بدون تعليمات صريحة. هههه

إذا كنت لا تعرف كيفية استخدام أداة مثل nano، فقم بتشغيل discourse-setup مرة أخرى. بعد حفظ التغييرات، يمكنك الضغط على control-c ثم

./launcher destroy app;./launcher start app
إعجاب واحد (1)

حسناً، ولكن كيف يمكنني التحقق من الإعدادات في ملف containers/app.yml الخاص بي حتى أتمكن من إلقاء نظرة على قسم البريد الإلكتروني والتحقق من صحة البيانات؟

إذا لم تعجبك إجابتي، يمكنك البحث عن “nano” على جوجل.

يمكن القول إن OP يجب أن يقول شيئًا عن nano، على الرغم من ذلك، كما قلت، إذا كنت لا تعرف ما هو، فما عليك سوى تشغيل discourse-setup مرة أخرى، لأنه يقرأ القيم الموجودة في الملف ولا يمكنك إفساد التنسيق.

أرى ما تقصده الآن. عندما تقوم بتشغيل أوامر التدمير ثم البدء، يتم عرض البيانات التي أحتاجها بمجرد اكتمالها. اعتذاري! :slight_smile:

إعجاب واحد (1)

لقد قمت بتشغيل الأداة وحصلت على خطأ يقول SMTPAuthenticationError. تقول الأداة بعد ذلك أن هذا ليس خطأ شائعًا وليس لديهم اقتراحات حول كيفية إصلاحه. إذا حدث هذا، فتأكد من التحقق المزدوج من اسم مستخدم وكلمة مرور SMTP الخاصين بك، حيث أن عملية إعداد Discourse لا تخبرك إذا كانت خاطئة، فهي ببساطة لا تعمل (لا ترسل رسائل البريد الإلكتروني) وتتركك في حيرة. بعض الأشياء التي قمت بها والتي ساعدت هي تسجيل الدخول إلى الخادم الخاص بي باستخدام SSH باستخدام Ubuntu بدلاً من LISH (لأنني أستخدم Linode) لأن LISH مليء بالأخطاء بشكل رهيب ولا يدعم النسخ واللصق. ثم قمت بإعادة عملية الإعداد ونسخ ولصق كل شيء هذه المرة بدلاً من كتابة كلمات مرور مكونة من 100 حرف، هههه. على أي حال، آمل أن يساعد هذا بعض المبتدئين الآخرين هناك!

اسم المستخدم أو كلمة المرور لديك غير صحيحة.

لست متأكدًا من سبب عدم تمكني من إصلاح ذلك، ولكن الخطأ واضح جدًا.

قد يكون أنك نسخته ولصقته بشكل خاطئ. قد يكون به أحرف تحتاج إلى تهريب.

أستخدم Brevo كمرسل بريد إلكتروني للإشعارات الخاص بي، ومع ذلك تم رفض كل إشعار تم إرساله بسبب حدوث خطأ. وجدت رسالة في Brevo تفيد بأن “تم رفض الإرسال لأن المرسل الذي استخدمته غير صالح. تحقق من صحة المرسل الخاص بك أو قم بالمصادقة على نطاقك”. بسبب هذا، لا يمكن لمنتدى الخاص بي أن يعمل على الإطلاق. أتساءل كيف يمكنني استكشاف هذه المشكلة وإصلاحها - ما نوع المرسل الذي أحتاجه؟ شكراً جزيلاً!!!

بالنسبة لعنوان المرسل، يمكن تعيينه إلى نطاق فرعي للبريد الذي تستخدمه لإرسال البريد، مثل mail@domain_address.

للمصادقة على النطاق الفرعي + المرسل، هناك بعض الخطوات التي لديهم دليل لها هنا:

أهلاً بأشخاص Discourse!

لقد كافحت لعدة أيام مع ضبط معلمات البريد الإلكتروني باستخدام المنفذ 465، والحل ليس هنا ولا في أي منشور قرأته في المنتدى (وقد بحثت حقًا).

بالطبع، الأمر يتعلق بما يقبله خادم البريد الخاص بك. في حالتي، 465 فقط عبر TLS.

سطرا الإعداد المطلوبان لإضافتهما في app.yml هما:

DISCOURSE_SMTP_FORCE_TLS: true
DISCOURSE_SMTP_ENABLE_START_TLS: false
بعض التفاصيل

أسفرت الإعدادات الافتراضية عن خطأ Net::ReadTimeout عند تجربة بريد إلكتروني تجريبي باستخدام discourse-doctor. تعمل رسائل البريد الإلكتروني التجريبية من داخل الحاوية بشكل جيد باستخدام، على سبيل المثال، curl، تمامًا كما في هذا المنشور الذي قادني إلى نصف الحل: Cannot send email - problem with port 465 - #10 by schungx

لم أتمكن من معرفة الإعداد الثاني إلا بعد النظر في محتوى app.yml وتعديل هذا المعامل. لدي شعور بأن معظم البرامج (مثل Thunderbird) تقوم ضمنيًا بتعيين البروتوكول الصحيح عند اختيار المنفذ 465، فربما يجب أن يفعل Discourse ذلك؟ يبدو هذا قياسيًا حقًا، كما تم تسليط الضوء عليه هنا:

(رابط إلى المنشور الكامل)

لذلك، سأدافع حقًا عن تحديث قسم هذا الدليل حول المنفذ 465 أو جعل discourse-setup يختار تلقائيًا أفضل إعداد.

إعجابَين (2)

عادةً لا أعلق على الأشياء، لكن هذا كان مفيدًا بالفعل!
شكرًا يا رجل، يجب على القائم على صيانة ديسكورس تضمين هذا الإعداد في التكوين الافتراضي، أعني أنه كان من الصعب إعداد برامجهم، ومع ذلك ليس لدي ما أنتقده باستثناء أنه في مشروع كبير كهذا، فإن بعض المعلومات غير متاحة بسرعة ويجب على شخص ما أن “يتعمق”.
حسنًا، يعمل معي!

تم دمج منشور في موضوع موجود: استخدام % في كلمة مرور SMTP لـ discourse-setup