Rails 4 - yandex mail is not sending - ruby-on-rails

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.

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

how send mail with localhost using rails 4?

I search the equivalent to very simple PHP mail function, in ruby.
I watch http://guides.rubyonrails.org/action_mailer_basics.html and I trid to use it but it's not clear.
The only exemple I found on guide and on others responses on SO it's about "gmail smtp".
I don't want used gmail smtp, just local smtp server to test mail function like on WAMP.
I tried :sendmail delivery_method, but it respond "/bin/sendmail doesn't exist", so I install postfix in local and add this config to development.rb :
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
log of my rails server :
UserMailer#welcome_email: processed outbound mail in 2.4ms
Sent mail to test#mytruedomain.com (59.5ms) Date: Wed, 10 Dec 2014
12:08:02 +0100 From: contact#test.com To: mytruedomain.com
Message-ID: <5488299262e_17a43f9c2ba19314937e6#matrix-PC.mail>
Subject: test Mime-Version: 1.0 Content-Type: text/html;
charset=UTF-8 Content-Transfer-Encoding: 7bit
un test
but I never recieve it in my mail box at test#mytruedomain.com...
EDIT: when I watch log of postfix :
postfix/error[6335]: 7ECBD5C29E5: to=, relay=none, delay=0.14, delays=0.08/0/0/0.06, dsn=5.0.0, status=bounced (mytruedomain.com)
What specific config is missing/needed with my local postfix?
So how can I do to send mail? I just want send mail, I don't understand how it's so complicated !
First test if your server is working:
date | mail -s test your.name#domain.com
Then configure your application to send the email using smtp:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "localhost",
:port => 25,
:domain => "domain.com",
}
Try the code from Paulo Fidalgo, and I'll recommend you use mailcatcher.
Actually you just need this line in your development.rb file:
config.action_mailer.delivery_method = :smtp

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.

No errors in development.log, but mail wouldn't be sent

I use ActionMailer to send my email through Rails, but I can't receive anything.
My development.log said:
Sent mail to mymail#gmail.com (2107ms)
Date: Wed, 07 Dec 2011 17:14:30 +0800
From: no-reply
To: mymail#gmail.com
Message-ID: <4edf2e765a139_147105390c874e3#raincole-laptop.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>
Hello mymail#gmail.com!
</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p>Change my password</p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
But there is nothing new in my inbox or spam box.
I have set:
ruby-1.9.2-p290 :008 > Rails.application.config.action_mailer[:raise_delivery_errors]
=> true
So, how can I see the real error logs to debug?
Edit:
I write a email.yml:
development:
reply: "no-reply"
host: "starfish.dev"
smtp:
address: "smtp.gmail.com"
port: 587
domain: "starfish.dev"
authentication: "plain"
user_name: "mymail#gmail.com"
password: "mypassword"
enable_starttls_auto: true
Then in application.rb:
$EMAIL_CONFIG = ActiveSupport::HashWithIndifferentAccess.new YAML.load(File.open("#{Rails.root}/config/email.yml"))[Rails.env]
config.action_mailer.smtp_settings = $EMAIL_CONFIG[:smtp].symbolize_keys if !$EMAIL_CONFIG[:smtp].nil?
in development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
But, it still just sends to log file, no to real address.
The development and test environments don't use real mailers (unless you specifically configure them). By default it just does exactly what you have noticed: it goes through all the motions of sending an email... but then doesn't actually send it, just logs the email that would have been sent.
EDIT: note that this is a reply to the original question, which did not contain any smtp settings.
have you tried telnet smtp.yoursite.com 587?
if there's no responding, please check your firewall.

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.

Resources