2014-04-15 23:50:15 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'action_mailer'
|
|
|
|
|
|
|
|
# Make this your email address. Poor example.com gets SO MUCH MAIL
|
2017-07-27 21:20:09 -04:00
|
|
|
YOUR_EMAIL = "nobody@example.com"
|
2014-04-15 23:50:15 -04:00
|
|
|
|
|
|
|
# Change these to be the same settings as your Discourse environment
|
2017-07-27 21:20:09 -04:00
|
|
|
DISCOURSE_SMTP_ADDRESS = "smtp.example.com" # (mandatory)
|
|
|
|
@DISCOURSE_SMTP_PORT = 587 # (optional)
|
2014-04-15 23:50:15 -04:00
|
|
|
@DISCOURSE_SMTP_USER_NAME = "username" # (optional)
|
|
|
|
@DISCOURSE_SMTP_PASSWORD = "blah" # (optional)
|
|
|
|
#@DISCOURSE_SMTP_OPENSSL_VERIFY_MODE = "none" # (optional) none|peer|client_once|fail_if_no_peer_cert
|
|
|
|
|
|
|
|
# Note that DISCOURSE_SMTP_ADDRESS should NOT BE ALLOWED to relay mail to
|
|
|
|
# YOUR_EMAIL without authentication
|
|
|
|
MAILFROM = @DISCOURSE_SMTP_USER_NAME || YOUR_EMAIL
|
|
|
|
MAILTO = YOUR_EMAIL
|
|
|
|
|
|
|
|
### You shouldn't need to change anything below here
|
|
|
|
$delivery_options = {
|
|
|
|
user_name: @DISCOURSE_SMTP_USER_NAME || nil,
|
2018-12-04 04:48:16 -05:00
|
|
|
password: @DISCOURSE_SMTP_PASSWORD || nil,
|
|
|
|
address: DISCOURSE_SMTP_ADDRESS,
|
|
|
|
port: @DISCOURSE_SMTP_PORT || nil,
|
|
|
|
openssl_verify_mode: @DISCOURSE_SMTP_OPENSSL_VERIFY_MODE || nil
|
|
|
|
}
|
2014-04-15 23:50:15 -04:00
|
|
|
|
|
|
|
class EmailTestMailer < ActionMailer::Base
|
|
|
|
def email_test(mailfrom, mailto)
|
|
|
|
mail(from: mailfrom,
|
|
|
|
to: mailto,
|
|
|
|
body: "Testing email settings",
|
|
|
|
subject: "Discourse email settings test",
|
|
|
|
delivery_method_options: $delivery_options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
message = EmailTestMailer.email_test(MAILFROM, MAILTO)
|
|
|
|
|
|
|
|
begin
|
2014-10-15 03:04:47 -04:00
|
|
|
message.deliver_now()
|
2014-04-15 23:50:15 -04:00
|
|
|
rescue SocketError => e
|
2017-07-27 21:20:09 -04:00
|
|
|
print "Delivery failed: " + e.message.strip() + "\n"
|
2014-04-15 23:50:15 -04:00
|
|
|
print " Is the server hostname correct?\n"
|
|
|
|
rescue OpenSSL::SSL::SSLError => e
|
2017-07-27 21:20:09 -04:00
|
|
|
print "Delivery failed: " + e.message.strip() + "\n"
|
2014-04-15 23:50:15 -04:00
|
|
|
print " You probably need to change the ssl verify mode.\n"
|
|
|
|
rescue Net::SMTPAuthenticationError => e
|
2017-07-27 21:20:09 -04:00
|
|
|
print "Delivery failed: " + e.message.strip() + "\n"
|
2014-04-15 23:50:15 -04:00
|
|
|
print " Check to ensure your username and password are correct.\n"
|
|
|
|
rescue Net::SMTPFatalError => e
|
2017-07-27 21:20:09 -04:00
|
|
|
print "Delivery failed: " + e.message.strip() + "\n"
|
2014-04-15 23:50:15 -04:00
|
|
|
print " Check the above error and fix your settings.\n"
|
|
|
|
else
|
|
|
|
print "Successfully delivered.\n"
|
|
|
|
end
|