ActionMailer not sending emails in local environment - ruby-on-rails

I've configured my gmail variables in order to send test mails from my app:
application.rb
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'mail.google.com',
:port => 587,
:user_name => 'enriqueisasi#gmail.com',
:password => 'mypass',
:authentication => :plain,
:enable_starttls_auto => true
}
I can see in my logs its working, but I still don't see the emails in my Gmail:
Logs
Sent mail to enriqueisasi#gmail.com (219.7ms)
Date: Mon, 05 Sep 2016 01:32:55 +0200
From: Your Mailer <hola#benditapizza.es>
To: Me <enriqueisasi#gmail.com>
Message-ID: <57ccaf2742bc0_3d03ff35f488dec6265#MacBook-Pro-de-Enrique-2.local.mail>
Subject: Mensaje de adfadf
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit

I guess that you missed setting this config in development.rb
config.action_mailer.perform_deliveries = true
as by default this is on false, preventing mails to be sent from your development environment

Related

Rails 4 - yandex mail is not sending

In rails 4.2.4, I am using gem 'rails_config' for emails feature. In development environment all mails are sending properly but in test environment it is showing an error like Net::SMTPFatalError (553 5.7.1 Sender address rejected: not owned by auth user.):
In setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.yandex.ru",
:port => 465,
:domain => "yandex.ru",
:authentication => :login,
:user_name => "ssstest#yandex.com",
:password => "pwd567#",
:ssl=> true,
:enable_starttls_auto=> true,
:tls=> true
}
In user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "ssstest#yandex.com"
...
end
Server log's output is,
D, [2016-05-06T06:24:25.089270 #23566] DEBUG -- :
Devise::Mailer#confirmation_instructions: processed outbound mail in 954.3ms
I, [2016-05-06T06:24:26.500832 #23566] INFO -- :
Sent mail to sample_demo#yopmail.com (1408.8ms)
D, [2016-05-06T06:24:26.501240 #23566] DEBUG -- : Date: Fri, 06 May 2016 06:24:25 +0000
From: please-change-me-at-config-initializers-devise#example.com
Reply-To: please-change-me-at-config-initializers-devise#example.com
To: sample_demo#yopmail.com
Message-ID: <572c389917f09_5c0e10bb99411990#ip-10-65-178-51.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
How can I fix this issue? Please help me
As the error log indicates, please change the from email address inside config/initializers/devise.rb
config.mailer_sender = 'ssstest#yandex.com'
port: 465
authentication: login
smtp_enable_starttls_auto: true
smtp_openssl_verify_mode: true
As mentioned here
https://docs.gitlab.com/omnibus/settings/smtp.html#yandex
Have you added config.action_mailer.delivery_method = :smtp in the environments/test.rb ? And it is not a good practice to store usernames and passwords right in the email setup. Store them as environment variables.

Gmail not sending with env variables in Rails 4 project, but env variables are displayed in console

I am working on a tutorial about ActiveRecords and needed to configure ActionMailer.
I have Environmental Variables configured in ~/.bashrc and this system has been working reliably.
I configured everything in the development.rb
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
user_name: ENV[ "GMAIL_USERNAME" ],
password: ENV[ "GMAIL_PASSWORD"],
authentication: "plain",
enable_starttls_auto: true
}
My contact_form.rb model is:
class ContactForm < MailForm::Base
attribute :name, :validate => true
attribute :email, :validate => /\A([\w\.%\+\-]+)#([\w\-]+\.)+([\w]{2,})\z/i
attribute :message, :validate => true
# Declare the e-mail headers
def headers
{
:subject => 'ArcadeNomad - Contact Request',
:to => ENV[ "OWNER_EMAIL" ],
:from => ENV[ "OWNER_EMAIL" ]
}
end
end
When I test everything in rails console i get:
Machine:dev_arcadenomad_com Account$ rails c --sandbox
Loading development environment in sandbox (Rails 4.2.1)
Any modifications you make will be rolled back on exit
>> contact = ContactForm.new(:name => 'Name', :email => 'SomeMail#domain.tld', :message => 'I love ArcadeNomad!')
=> #<ContactForm:0x007fde0d6d38a8 #name="Name", #email="SomeMail#domain.tld", #message="I love ArcadeNomad!">
>> contact.valid?
=> true
>> contact.deliver
Rendered /Users/MyAccount/.rvm/gems/ruby-2.2.1#learn-active-records/gems/mail_form-1.5.1/lib/mail_form/views/mail_form/contact.erb (8.1ms)
MailForm::Notifier#contact: processed outbound mail in 239.6ms
Sent mail to mymail#gmail.com (6.9ms)
Date: Sat, 27 Jun 2015 17:32:01 +0200
From: mymail#gmail.com
To: mymail#gmail.com
Message-ID: <LongString#machine.domain.tl.mail>
Subject: ArcadeNomad - Contact Request
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<h4 style="text-decoration:underline">ArcadeNomad - Contact Request</h4>
<p><b>Name:</b>
Name</p>
<p><b>Email:</b>
SomeMail#domain.tld</p>
<p><b>Message:</b>
I love ArcadeNomad!</p>
=> true
But no mail is delivered.
If I hardcode my credentials into development.rb everything works.
When I test for ENV[ "GMAIL_USERNAME" ] in rails console my mail credentials are displayed correctly.
What am I missing?

sendmail with RoR: not receiving mails

I am using sendmail in my Rails app. The configrations are as given below,
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost' }
config.action_mailer.default_options = {from: 'no-reply#example.com'}
config.action_mailer.delivery_method = :sendmail
When I restart my apache2 server and sendmail service, I will get a mail(one time). However, if, later, I try to send the mail, it shows the status as 200-ok, but I won't receive any mail.
FYI:
Same issue is found even for localhost:3000
Also below is my mail.log output
Nov 25 17:58:02 dosysnet267 sendmail[1602]: sAPCS2X3001602: Authentication-Warning: dosysnet267.dreamorbit.in: DREAMORBIT\\karthik.ds set sender to no-reply#gmail.com using -f
Nov 25 17:58:02 dosysnet267 sendmail[1602]: sAPCS2X3001602: from=no-reply#gmail.com, size=473, class=0, nrcpts=1, msgid=<547475d2aa8c3_5dc181896c66978#dosysnet267.mail>, relay=DREAMORBIT\\karthik.ds#localhost
Nov 25 17:58:03 dosysnet267 sm-mta[1604]: sAPCS2bg001604: from=<no-reply#gmail.com>, size=774, class=0, nrcpts=1, msgid=<547475d2aa8c3_5dc181896c66978#dosysnet267.mail>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Nov 25 17:58:03 dosysnet267 sendmail[1602]: sAPCS2X3001602: to=karthik.ds#example.com, ctladdr=no-reply#gmail.com (1200096887/1200095745), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30473, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (sAPCS2bg001604 Message accepted for delivery)
Nov 25 17:58:05 dosysnet267 sm-mta[1609]: sAPCS2bg001604: to=<karthik.ds#example.com>, delay=00:00:03, xdelay=00:00:02, mailer=esmtp, pri=120774, relay=example.com. [174.136.95.75], dsn=2.0.0, stat=Sent (OK)
Any idea?
When i need to send a email when testing an rails app do i all ways use this code inside the development file. Then just fill it out with your gmail credentials. The rails app will then send the email through gmail with your gmail account.
config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'youremail#gmail.com',
:password => 'yourpassword',
:authentication => 'plain',
:enable_starttls_auto => true }
config.action_mailer.default_url_options = { :host => "localhost:3000" }
Thanks for looking into the issue. It is working fine. I couldn't receive mails, due to my mailbox issues.

Sending email from Gmail Rails 3

I'm trying to send an email through my gmail account. I copied the code directly from the rails guide, and in my terminal it's saying that it is sending the message however, the address I'm sending it to is not getting it. Here is the code I have in my env.rb file
config.action_mailer.deconfig.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'derp'
:user_name => 'derp.bot',
:password => 'derp42069',
:authentication => 'plain',
:enable_starttls_auto => true }
In the terminal, I'm getting the following message:
Sent mail to derpviolin#gmail.com (20ms)
Date: Wed, 16 Feb 2011 23:09:54 -0800
From: derp.bot#gmail.com
To: derpviolin#gmail.com
Message-ID: <4d5cc9c2d6448_f88819dd6287289#dn0a203255.sunet.mail>
Subject: New Task
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
you suck
Rendered need_router/index.html.erb within layouts/application (2.1ms)
Completed 200 OK in 371ms (Views: 8.3ms)
However the email I'm sending it to is not receiving the message. Any help would be greatly appreciated.
See here for answer to similar problem.

ActionMailer emails "sent" in development.log, but not received

I'm having problems actually sending via ActionMailer in development, on my localhost, with Rails 2.3.2 and Ruby 1.8.6. The development.log shows that it has "sent" the email with no errors, but the email is not received. I have tried multiple email addresses for sending and receiving and have tried multiple configs and plugins, but cannot get the email to send. Any help would be much appreciated - I feel like I'm dancing around a bunch of versions of solutions for different versions of rails and ruby and can't nail it down. I would much appreciate any comments. Thanks!
Plugins:
action mailer optional tls
smtp_tls
Different email configs:
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true, #works in ruby 1.8.7 and above
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'example.com',
:authentication => :plain,
:user_name => 'testacct',
:password => 'secret'
}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:tls => :true,
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:user_name => 'testacct#gmail.com',
:password => 'secret'
#:enable_starttls_auto => true # for rails >= 2.2 && ruby >= 1.8.7
}
config.action_mailer.perform_deliveries = :true #try to force sending in development
config.action_mailer.raise_delivery_errors = :true
config.action_mailer.default_charset = "utf-8"
Development.log:
Sent mail to sa23kdj#trash2009.com
Date: Fri, 18 Dec 2009 00:27:06 -0800
From: Test Email Acct <testacct#gmail.com>
To: sa23kdj#trash2009.com
Subject: Signup
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4b2b3cda9088_634334302a5b7
--mimepart_4b2b3cda9088_634334302a5b7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww=
w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang=3D'en' xml:lang=3D'en' xmlns=3D'http://www.w3.org/1999/xhtml'>=
<head>
<meta content=3D'text/html;charset=3DUTF-8' http-equiv=3D'content-typ=
e' />
</head>
<body>
Welcome Email
<p>
user name:
lfglkdfgklsdf
activation link:
http://localhost:3000/login
</p>
</body>
</html>
--mimepart_4b2b3cda9088_634334302a5b7--
Put the following in config/environments/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
It will override the settings in config/environment.rb
Also for rails 2.X you'll need to setup:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.com",
:user_name => "username#domain.com",
:password => "secret_passsword",
:authentication => :plain
}
You need to use true and not :true.
:tls => true
...
config.action_mailer.perform_deliveries = true #try to force sending in development
config.action_mailer.raise_delivery_errors = true
In case anyone faces this problem, set "config.action_mailer.raise_delivery_errors = true" in development.rb in your environments folder and try sending mail again. This should raise whatever error is being encountered.
Sometimes in line 8 of smtp_tls.rb , the check_auth_args method accepts only 2 arguments : user and secret. Remove the 'authtype' argument if you see it and try again. Should work.

Resources