Sending email from Gmail Rails 3 - ruby-on-rails

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.

Related

ActionMailer not sending emails in local environment

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

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?

Sending mail with ActionMailer and Outlook/Mandrillapp SMTP server

I am using ActionMailer to send mails for a 'Contact Us' form in my application.
I am using Mandrill app for sending my emails.These are my settings:
config/environments/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => 'SMTP username i.e Mandrill a/c username',
:password => 'API key for development',
:domain => 'example.com',
:authentication => 'plain'
}
config/environments/production.rb
I have removed the line
config.action_mailer.raise_delivery_errors = true
and changed the password for production - which is Mandrill app API key for production.
app/mailers/contactus_mailer.rb
class ContactusMailer < ActionMailer::Base
default :from => "noreply#example.com"
default :to => "help#example.com"
def new_message(message)
#message = message
mail(:subject => "[WebsiteName] #{message.name + " - " + message.email}")
end
end
Validity of the above accounts on custom domain - example.com
The above email accounts i.e noreply#example.com & help#example.com are provisioned and fully functional. The above accounts are setup at Outlook.com and I have also double-checked the MX records for my domain example.com and the domain settings are Active for my domain. As a proof, I can send/receive emails on both accounts from the accounts.
Development and Production environment Logs:
When I use the Contact Us form in both environments, ActionMailer reports no errors and redirects successfully to Home page.
Started POST "/contact" for 127.0.0.1 at 2013-08-18 12:35:37 +0530
Processing by MessagesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"UNgMrA04yk4sIbqtXjlLvLvDINgrBT5eP0wMSRYNgPs=", "message"=>{"name"=>"Dummy name", "email"=>"abc#pqr.com", "content"=>"Random body"}, "commit"=>"Send Message"}
Rendered contactus_mailer/new_message.text.erb (0.5ms)
Sent mail to help#example.com (2679ms)
Date: Sun, 18 Aug 2013 12:35:38 +0530
From: noreply#example.com
To: help#example.com
Message-ID: <52107242dbf6c_12a7f3fd8b1835ad03979#Jatins-MacBook-Pro.local.mail>
Subject: [WebsiteName] Dummy name - abc#pqr.com
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Name: Dummy name
Email: abc#pqr.com
Body: Random body
Redirected to http://localhost:3000/
Completed 302 Found in 3841ms (ActiveRecord: 0.0ms)
Mandrill App API log for Production environment:
Full Request:
{
"from_email": null,
"from_name": null,
"async": false,
"key": "API key for production",
"raw_message": "Received: from example.com (unknown [23.20.245.109])\n\t(Authenticated sender: key_production#gmail.com)\n\tby ip-10-31-147-25 (Postfix) with ESMTPSA id 6811A151A064\n\tfor <help#example.com>; Sun, 18 Aug 2013 08:19:11 +0000 (UTC)\nDate: Sun, 18 Aug 2013 08:19:11 +0000\nFrom: noreply#example.com\nTo: help#example.com\nMessage-ID: <5210837f5ce24_26e56b87992f#5c11fd99-5533-4855-af78-40e02c939412.mail>\nSubject: [WebsiteName] Dummy name - abc#pqr.com\nMime-Version: 1.0\nContent-Type: text/plain;\n charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\nName: Dummy name\n\nEmail: abc#pqr.com\n\nBody: Random body",
"to": [
"help#example.com"
]
}
Full Response:
[
{
"email": "help#example.com",
"status": "rejected",
"_id": "9c9f88c588ee4f369437b8dd5d531c8c",
"reject_reason": "soft-bounce"
}
]
Mandrill App API log for development environment:
The Full Request for development env. is similar to the production environment. However, in development the response is different.
Full Response:
[
{
"email": "help#example.com",
"status": "sent",
"_id": "e67f31f893a84ecdb0ed2438e5741ce1",
"reject_reason": null
}
]
NOTE: I am not getting email on my account help#example.com in both development and production environments.
Queries:
Why am I getting rejected status and soft-bounce reject reason for production env., whereas for development it says sent status and no reject reason.
Why am I not receiving any mails in both the cases?
P.S.
Initially, I wasn't using Mandrill app and was using smtp.live.com as my SMTP server along with my no reply#example.com credentials, but that didn't work out.
Then I switched to Mandrill after some digging on Google.
It'd be equally good if someone can help with the Outlook mail setup. That way, Mandrill won't be required at all.
I got it working with and without Mandrill. I didn't get any emails until 7 days later, my inbox was flooded with all my test emails.
Seems there was a glitch with my DNS, TXT records for my email account, which had caused the delay.
Also tried without Mandrill, and the mails are getting sent properly. So, posting the settings for Outlook here. Might come handy for someone else.
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.live.com",
:port => 587,
:enable_starttls_auto => true,
:user_name => 'noreply#example.com',
:password => 'password',
:domain => 'example.com',
:authentication => 'plain'
}
Note: For use in production, set raise_delivery_errors to false.
Do you have
config.action_mailer.default_url_options = {
:host => 'YOUR_HOST_NAME_HERE'
}
defined in application.rb or production.rb? It should be set to your domain name. I've found that some servers will reject mail without an explicitly defined hostname.

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