Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

SMTP no longer works on newest builds

Open doomdance opened this issue 11 years ago • 10 comments

I've built RC several times in the past weeks and implimented SMTP successfully each time. As of yesterday I have attempted two builds, each on clean servers, and one local build with meteor and sending emails through SMTP does not work on any of them. I have tested with multiple SMTP accounts as well and monitoring outgoing network connections (nothing). When I finally deployed locally I was able to see the following output in my terminal:

-20:27:47.910(-5)? ====== BEGIN MAIL #2 ======
I20150926-20:27:47.910(-5)? (Mail not sent; to enable sending, set the MAIL_URL environment variable.)
I20150926-20:27:47.910(-5)? MIME-Version: 1.0
I20150926-20:27:47.910(-5)? From: "Rocket.Chat" <[email protected]>
I20150926-20:27:47.910(-5)? To: [email protected]
I20150926-20:27:47.910(-5)? Subject: How to verify email address on Rocket.Chat
I20150926-20:27:47.910(-5)? Content-Type: text/plain; charset=utf-8
I20150926-20:27:47.910(-5)? Content-Transfer-Encoding: quoted-printable
I20150926-20:27:47.910(-5)? 
I20150926-20:27:47.910(-5)? Hello,
I20150926-20:27:47.911(-5)? 
I20150926-20:27:47.911(-5)? To verify your account email, simply click the link below.
I20150926-20:27:47.911(-5)? 
I20150926-20:27:47.911(-5)? http://localhost:3000/login/#/verify-email/0dt-_2PFYTa8rK49BXsi9Q_E2ljFURJRcEJ926LUwWr
I20150926-20:27:47.911(-5)? 
I20150926-20:27:47.911(-5)? Thanks.
I20150926-20:27:47.911(-5)? 
I20150926-20:27:47.911(-5)? ====== END MAIL #2 ======

Bear with me as I'm not a developer but I also see there changes made a few days ago: https://github.com/RocketChat/Rocket.Chat/search?utf8=%E2%9C%93&q=MAIL_URL

Could these be the cause?

doomdance avatar Sep 27 '15 01:09 doomdance

Thanks for bringing that up @doomdance, I was in the process of submitting an issue about this myself.

I use Mandrill for delivery and it worked fine until I pulled latest code from GH. I do not have any details at hand at the moment because I'm "on the go".

However, you're not alone with having this issue.

k0nsl avatar Sep 27 '15 01:09 k0nsl

Okay, so I just tested it and I'm receiving the same message as @doomdance.

I20150926-21:29:10.172(-5)? (Mail not sent; to enable sending, set the MAIL_URL environment variable.)

k0nsl avatar Sep 27 '15 02:09 k0nsl

Are you setting MAIL_URL? I assume no?

The loading of settings was recently changed to load quicker. I don't see anything else in the last few days involving that. We'll take a look.

geekgonecrazy avatar Sep 27 '15 04:09 geekgonecrazy

It's because we're loading settings ASAP instead of waiting for Meteor.startup (like we used to). MAIL_URL is never set because RocketChat.settings.get calls returns undefined when the following code is executed:

if process?.env? and not process.env['MAIL_URL']? and RocketChat.settings.get('SMTP_Host') and RocketChat.settings.get('SMTP_Username') and RocketChat.settings.get('SMTP_Password')
        process.env['MAIL_URL'] = "smtp://" + encodeURIComponent(RocketChat.settings.get('SMTP_Username')) + ':' + encodeURIComponent(RocketChat.settings.get('SMTP_Password')) + '@' + encodeURIComponent(RocketChat.settings.get('SMTP_Host'))
        if RocketChat.settings.get('SMTP_Port')
            process.env['MAIL_URL'] += ':' + parseInt(RocketChat.settings.get('SMTP_Port'))

RocketChat.settings uses Meteor.settings behind the scenes, and even though we "add" the values, they aren't available until Meteor is fully initialized. Thus, we need to wrap it with Meteor.startup e.g.


Meteor.startup ->
    if process?.env? and not process.env['MAIL_URL']? and RocketChat.settings.get('SMTP_Host') and RocketChat.settings.get('SMTP_Username') and RocketChat.settings.get('SMTP_Password')
        process.env['MAIL_URL'] = "smtp://" + encodeURIComponent(RocketChat.settings.get('SMTP_Username')) + ':' + encodeURIComponent(RocketChat.settings.get('SMTP_Password')) + '@' + encodeURIComponent(RocketChat.settings.get('SMTP_Host'))
        if RocketChat.settings.get('SMTP_Port')
            process.env['MAIL_URL'] += ':' + parseInt(RocketChat.settings.get('SMTP_Port'))

rwakida avatar Sep 27 '15 05:09 rwakida

SMTP for account registration now works but it is still broken for password resetting and re-sending email confirmation.

doomdance avatar Sep 28 '15 23:09 doomdance

@doomdance confirmed that password reset and re-send email confirmation not working. I found the problem, will submit pull request later tonight.

btw, how did you get to the re-send email confirmation page? I had to hack the login to get to it.

rwakida avatar Sep 29 '15 01:09 rwakida

@rwakida If you try logging in as a user that is not verified, it should take you to this prompt. screenshot from 2015-09-28 20-57-37

doomdance avatar Sep 29 '15 01:09 doomdance

Cool. Thanks @doomdance. Not sure why I couldn't get to that before....oh well. I'll submit a pull request tonight.

rwakida avatar Sep 29 '15 02:09 rwakida

Anytime! And thank you, @rwakida!

doomdance avatar Sep 29 '15 02:09 doomdance

I think Im seeing this issue on an instance I built a couple of weeks ago. Im struggling to work out how to tell what version of rocket chat I have installed currently. I can't find anything visible in the UI, or in the app.json etc. Do you know what release this was fixed in, and how I tell what version I currently have installed ?

rasathus avatar Nov 13 '15 09:11 rasathus