ActionMailer Successful outbound email but not receiving - ruby-on-rails

I looked around for similar issues but nothing seems to work for me.
I'm using ActionMailer
to send emails. The email outbound went through successfully but I I'm not receiving it in my email.
I have enabled POP mail service.
config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "tvtt.co",
:user_name => "postmaster#tvtt.co",
:password => "password"
}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
mailers/notification_mailer.rb
class NotificationMailer < ActionMailer::Base
default from: 'support#tvtt.com'
def acquisition_email(listing)
#neighborhood = listing.neighborhood
#tenant_fee = listing.tenant_fee
#listing = listing
mail(
to: "yseremail#gmail.com",
subject: "List your place on tvtt!"
)
end
end
And here is the "successful" output for the email outbound:
Sent mail to yseremail#gmail.com (23.1ms)
Date: Sat, 12 Dec 2015 20:05:13 -0500
From: support#tvtt.com
To: yseremail#gmail.com
Message-ID: <566cc44930cf0_64f23fc8933831dc28566#yseremail-MacBook-Pro.local.mail>
Subject: List your place on tvtt!
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Related

Emails not sending in Heroku using Postmark

When on Heroku my custom mailer does not send, I get no errors at all. This is the log -
Spree::HmsCommunicator#progress_email: processed outbound mail in 5.5ms
=> nil
It works perfectly fine in development -
Spree::HmsCommunicator#progress_email: processed outbound mail in 1178.4ms
Sent mail to blah#thehandbagspa.com (983.0ms)
Date: Tue, 19 Jan 2016 08:30:54 +0000
From: blah#thehandbagspa.com
To: blah#thehandbagspa.com
Message-ID: <569df43e70279_fe9a3ff1ae06020465535#Andrews-MacBook-Pro.local.mail>
Subject: Handbag Update | The Handbag Spa
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_569df43e6d9de_fe9a3ff1ae0602046541e";
charset=UTF-8
Content-Transfer-Encoding: 7bit
track-opens: true
application.rb -
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :postmark
config.action_mailer.perform_deliveries = true
config.action_mailer.postmark_settings = { :api_token => "***...." }
hms_communicator.rb -
module Spree
class HmsCommunicator < BaseMailer
require 'twilio-ruby'
def progress_email(handbag, stage, movedTo)
#handbag = handbag
#stage = stage
#movedTo = movedTo
mail(:subject => 'Handbag Update | The Handbag Spa',
:to => #handbag.user.email,
:from => 'blah#thehandbagspa.com',
:track_opens => 'true')
#send_text_message
end
def test_email
mail(:subject => 'Handbag Update | The Handbag Spa',
:to => 'blah#thehandbagspa.com',
:from => 'blah#thehandbagspa.com',
:body => 'hey',
:track_opens => 'true')
end
def send_text_message
account_sid = '****...'
auth_token = '****...'
alphanumeric_id = "TheHandbagS"
twilio_phone_number = '+..'
recipient_phone_number = '+..'
client = Twilio::REST::Client.new(account_sid, auth_token)
begin
client.messages.create(
from: alphanumeric_id,
to: recipient_phone_number,
body: "Hello Freya. We have received your item into the spa. It will be enjoying it's first treatment shortly. Love, The Handbag Spa"
)
rescue Twilio::REST::RequestError => error
if error.code == 21612
client.messages.create(
from: twilio_phone_number,
to: recipient_phone_number,
body: "Hello, this is a message from Andrew"
)
else
# handle this some other way
raise error
end
end
end
end
end
Trying these mail commands from the console locally works fine and I get the email returned in the console but in heroku console they return a nil object -
Spree::HmsCommunicator#progress_email: processed outbound mail in 5.0ms
=> #<ActionMailer::Base::NullMail:0x007fc9cc5c19b0>
However this works fine in the Heroku console?? -
ActionMailer::Base.mail(from: "test#example.co", to: "valid.recipient#domain.com", subject: "Test", body: "Test").deliver_now
I'm dying here, I need some help!

Set up mandril with mail catcher in rails

I am using mandril with action mailer.
On my mandril config
ActionMailer::Base.smtp_settings = {
:port => '587',
:address => 'smtp.mandrillapp.com',
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY'],
:domain => ENV['MANDRILL_DOMAIN'],
:authentication => :plain
}
ActionMailer::Base.delivery_method = :smtp
MandrillMailer.configure do |config|
config.api_key = ENV['MANDRILL_API_KEY']
end
Rails.application.config do |config|
config.mandrill_mailer.default_url_options = { host: ENV['DEFAULT_URL_HOST'] }
config.mandrill_mailer.default_url_options['protocol'] = ENV['DEFAULT_URL_PROTOCOL'] unless ENV['DEFAULT_URL_PROTOCOL'].blank?
end
On the action_mailer.rb
Rails.application.configure do
config.action_mailer.default_url_options = { host: ENV['DEFAULT_URL_HOST'] }
config.action_mailer.default_url_options['protocol'] = ENV['DEFAULT_URL_PROTOCOL'] unless ENV['DEFAULT_URL_PROTOCOL'].blank?
end
On the development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
I am running mail catcher and visiting http://localhost:1080/ but it doesn't work,
do I need to add more configurations ?
I'm using the default smpt_settings with mailcatcher in dev mode. so I didnt specify the
config.action_mailer.smtp_settings = ..
at all.
But I have to launch mailcatcher in the foreground with
mailcatcher -f
for it to work (it's somehow buggy as deamon). This has the advantage, that you can see if it receives the mail requests.

530-5.5.1 Authentication Required. Learn more at

In order_mailer.rb:
default from: 'notifications#example.com'
def welcome_email(order)
#user = "Uday kumar das"
#url = 'http://example.com/login'
mail(to: 'dasudaykumar017#gmail.com', subject: 'Welcome to My Awesome Site')
end
In orders_conroller:
def delivery
#order1 = Order.where(:orderId=>params[:orderId])
#order = Order.find(#order1)
OrderMailer.welcome_email(#order).deliver
end
In environments/development.rb:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
I am new to mails in rails.I am referring http://guides.rubyonrails.org/action_mailer_basics.html to learn. I am getting error like:
Net::SMTPAuthenticationError in OrdersController#delivery`
530-5.5.1 Authentication Required. Learn more at`
I did the same using my gmail, following are my configurations, try and see it if works
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:user_name => "<my gmail>#gmail.com",
:password => "<my gmail password>",
:openssl_verify_mode => 'none' }
Please note the:
:openssl_verify_mode => 'none'
section to skip the ssl errors

emails: server sends but a user doesn't receive

I'm facing a weird bug.
Trying to set up welcome email after a user's registration.
According to server logs, my code sends an email but a user doesn't receive it.
Here is my code:
models/user.rb
after_create :welcome_message
private
def welcome_message
UserMailer.welcome_email(self).deliver
end
and mailers/user_mailer.rb
def welcome_email(user)
#user = user
mail to: #user.email, subject: t("mailer.welcome_email.welcome")
end
here are environments. The error occurs in both of them
config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: '587',
domain: 'localhost:3000',
user_name: 'welcome#mysite.com',
password: 'blahblahblah',
authentication: 'plain',
enable_starttls_auto: true
}
and config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'mysite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: '587',
domain: 'mysite.com',
user_name: 'welcome#mysite.com',
password: 'blahblahblah',
authentication: 'plain',
enable_starttls_auto: true
}
I'm using Devise to register users. So, also tried to do that via :confirmable. Outcome is the same – test user doesn't get a welcome email.
Gemfile
gem 'rails', '3.2.12'
gem 'devise', '3.0.3'
gem "mail"
and here are server logs
Sent mail to user#hismail.com (1920ms)
Date: Sat, 10 May 2014
From: welcome#mysite.com
Reply-To: welcome#mysite.com
To: user#hismail.com
Message-ID: <aaa#aaa.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome user#hismail.com!</p>
Yet eventually there is no welcome email at user#hismail.com
Any ideas?
UPD:
on the internet I see that nobody else faces the same problem
So, I guess I'm just missing something. But cannot figure out what and where. Please help me.
Try this:-
Create a file named as setup_mail.rb in config/initializers/ folder so that it looks like
config/initializers/setup_mail.rb
and put the below code in that file:-
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.mandrillapp.com",
:domain => "mysite.com",
:port => 80,
:user_name => "username",
:password => "blahblahblah",
:authentication => :plain
}
ActionMailer::Base.default_url_options[:host] = "mysite.com"
Delete this from config/environments/development.rb and config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: '587',
domain: 'localhost:3000',
user_name: 'welcome#mysite.com',
password: 'blahblahblah',
authentication: 'plain',
enable_starttls_auto: true
}

Attaching PDF's to Emails in Rails 2

I am sending an email in my Rails 2 app and after a bit of hacking and learning about emails in Rails it now works fine.
Now I am just trying to add an attachment which in theory should probably be straightforward but I seem to be having issues with it.
I am using mailcatcher to preview the emails in the development environment and I can see the attachment headers in the email source but nothing is shown in mailcatcher (docs say it supports attachments)
emailer.rb
class Emailer < ActionMailer::Base
def quotation_notification(q)
#recipients = q.recipient_email
#from = q.partner_name + "<#{q.partner_email}>"
#subject = "New Quotation from " + q.partner_name
#sent_on = Time.now
#quote_id = q.quote_id
#customer_id = q.customer_id
#customer_name = q.customer_name
#recipient_email = q.recipient_email
#partner_name = q.partner_name
#partner_email = q.partner_email
#partner_ref = q.partner_ref
#version_no = q.version_no
#line_items = q.line_items
#quotation_date = q.quotation_date
content_type "multipart/alternative"
part "text/html" do |p|
p.body = render_message("quotation_notification.text.html.rhtml", :message => q)
end
attachment :content_type => "application/pdf",
:body => File.read(RAILS_ROOT + '/pdfs/' + q.quote_id + '.pdf')
#body[:q] = q
end
end
The email is being sent in a controller like so
q = QuotationEmail.new(quote_id, customer_id, customer_name, recipient_email, partner_name, partner_email, partner_ref, version_no, line_items, quotation_date)
# send email
Emailer.deliver_quotation_notification(q)
Just for completeness, my view is app/views/emailer/quotation_notification.text.html.rhtml
quotation_email.rb
class QuotationEmail
attr_accessor :quote_id, :customer_id, :customer_name, :recipient_email, :partner_name, :partner_email, :partner_ref, :version_no, :line_items, :quotation_date
def initialize(quote_id, customer_id, customer_name, recipient_email, partner_name, partner_email, partner_ref, version_no, line_items, quotation_date)
#quote_id = quote_id
#customer_id = customer_id
#customer_name = customer_name
#recipient_email = recipient_email
#partner_name = partner_name
#partner_email = partner_email
#partner_ref = partner_ref
#version_no = version_no
#line_items = line_items
#quotation_date = quotation_date
end
end
In the source of the email, after the closing html tag I can see
--mimepart_522da7e7e5959_a0885cd9314396
Content-Type: application/pdf
Content-Transfer-Encoding: Base64
Content-Disposition: attachment
*base 64 encoded stuff*
--mimepart_522da7e7e5959_a0885cd9314396--
If I have done anything bonkers then it is because I haven't sent any emails in Rails yet so still figuring things out.
I can only assume this was a problem with mailcatcher, by setting up development emails to be sent to a gmail account, the emails were sent correctly with attachments.
environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.co.uk",
:user_name => "gmailaddress#domain.co.uk",
:password => "accountpassword",
:authentication => :plain,
:enable_starttls_auto => true #This line is must to ensure the tls for Gmail
}
I used an existing app email address hosted on gmail, so not strictly an username#gmail.com / username#googlemail.com but I would think that those addresses would also work with the above.

Resources