I'm working with an old RefineryCMS 1.0.8 project and migrating it to another server. It all works apart from the contact us form.
Here is my setup in the production.rb file
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
# location: '/usr/sbin/sendmail',
# arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
if ENV['MAILER_USERNAME'].present? && ENV['MAILER_PASSWORD'].present?
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "my_domain.com.au",
user_name: "#{ENV['MAILER_USERNAME']}",
password: "#{ENV['MAILER_PASSWORD']}",
authentication: 'plain',
enable_starttls_auto: true
}
end
I've set the environment variables in my /etc/environment and /etc/apache2/envvars files like so;
export MAILER_USERNAME="<email address>"
export MAILER_PASSWORD="<password>"
I've also set the tld to a length of 2 as we are in Australia so we are using a .com.au. This is set in my config/application.rb
config.action_dispatch.tld_length = 2
Here is the error I get;
Sent mail to <my gmail address> (2924ms)
There was an error delivering an inquiry confirmation:
555 5.5.2 Syntax error. w20sm33182626pfi.31 - gsmtp
You should wrap your email in <> blocks.
export MAILER_USERNAME="<map#gmail.com>"
export MAILER_PASSWORD="password"
I found the problem was not the brackets around the email it was the fact that I hadn't setup the DNS to that machine yet. Once I did that last night and went to the refinerycms website at it's domain instead of the IP then I could send emails.
Related
I am working on a basic app called PhotoApp, where I am learning how to set up SMTP with rails. I have used basic Ruby with SMTP sometime ago, and I know my email works, just the emails sent gets to spam folder.
But when I am trying to configure SMTP on Rails, I am getting ArgumentError (SMTP-AUTH requested but missing user name):, and that's the primary reason why the app, when pushed to heroku, crashed every time a user signs up.
Here's my config/environments/development.rb:
config.action_mailer.default_url_options = { host: 'localhost:8080' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.net',
authentication: 'plain',
enable_starttls_auto: true,
user_name: 'gmail_email',
password: '...'
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
I am running the server on localhost:8080, in development mode, so my host is set to localhost:8080.
Apart from that I am not able to get my app working with my gmail username with SMTP in rails.
Edit, this ruby code works:
#!/usr/bin/ruby -w
require 'net/smtp'
message = <<~EOF
From: mygmail#gmail.com
To: someone#protonmail.com
Subject: Hello!
Hello!
#{"HELLO ".*(50).delete_suffix(?\s)}
EOF
Net::SMTP.new('smtp.gmail.com', 587).tap(&:enable_starttls_auto).start('gmail.com', 'mygmail#gmail.com', 'mygmailpass', :plain) do |smtp|
smtp.send_message message, 'mygmail#gmail.com', 'someone#protonmail.com'
end
But as a newbie to rails, I can't get actionmailer working when the same email is used in the config file...
I have a action mailer method as something like this:
def mail
#receiver = User.where(status: 2).pluck(:email)
mail(bcc:#receiver, to: "username#gmail.com")
end
application.yml looks like this:
SMTP_ADDRESS: 'smtp.gmail.com'
SMTP_PORT: 587
SMTP_HOST: 'localhost:3000'
SMTP_DOMAIN: 'localhost:3000'
SMTP_USERNAME: 'user#gmail.com'
SMTP_PASSWORD: 'xxxxx'
SUPER_ADMIN_EMAIL: 'super_admin#mailinator.com'
developmet.rb looks like this:
config.action_mailer.asset_host = ENV["SMTP_HOST"]
# config.action_mailer.delivery_method = :letter_opener
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
#Enter the smtp provider here ex: smtp.mandrillapp.com
address: ENV["SMTP_ADDRESS"],
port: ENV['SMTP_PORT'].to_i,
#Enter the smtp domain here ex: vendaxo.com
domain: ENV["SMTP_DOMAIN"],
#Enter the user name for smtp provider here
user_name: ENV["SMTP_USERNAME"],
#Enter the password for smtp provider here
password: ENV["SMTP_PASSWORD"],
authentication: 'plain',
enable_starttls_auto: true
Where receivers are kept in BCC but "username#gmail.com" will be able to see the BCCd receivers. This is working fine when I send the mails from my local host. When receivers are sent emails, all of them are in BCC and one 'username#gmail.com' is able to see all the receivers.
But when I do the same thing on production server with similar application.yml configuration changing the host and port the username#gmail.com is NOT GETTING the emails of BCCd receivers.
I think if you are running your production server on AWS EC2 (may be other providers too), every time you do some changes to your application.yml or any other shared file, you need to restart the app server in order to apply the changed configurations . In my case I had to restart the PUMA, and the one default email started to get BCCd email ids.
I am trying to send mail through sendgrid from my rails app. I have setup sendgrid previously. I was able to send and receive mail in the development and the production, through heroku. Everything worked for a day. I came back a couple of days later and nothing worked.
There are no errors. In dev it says the mail is sent but the email doesn't send and same for production.
Here is my setup:
development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
production.rb
config.action_mailer.default_url_options = { host: 'herokuapp.com' }
Rails.application.routes.default_url_options[:host] = 'herokuapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
setup_mail.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
:authentication => :plain,
user_name: 'user',
password: 'pass',
domain: 'herokuapp.com',
enable_starttls_auto: true
}
I have tried resetting my pass to sendgrid and removing then re-adding it but then I run into an error saying "user banned" and I am unable to re add it.
I have also tried switching to postmark with similar results where the mail is never received but is sent.
You should check on Sendgrid if they are receiving your email requests.
From the documentation:
Search for the email in Email Activity. If we successfully delivered the message you will see a delivered event with the time of delivery. If you do not see the email come up, you can click on search options and make sure processed and deferred are checked. A processed event indicates that we actually got the request from you. Deferred events show if there are issues or delays with the receiving server accepting the message.
please help solve the problem.
i use webrick server on localhost. in development.rb i registered:
config/enviroments/development.rb:
Rails.application.configure do
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
i use gem devise. and i user 'forgot youre password'-function (devise-recoverable module). the result did not get to the email message. but where can I find a mark(log) that was an attempt to send a letter? whether there is a directory where they are stored?
You will need to edit your config/environments/development.rb file.
Here's something to get you started, add this to that file:
# port 3000 or whatever port you are using for your localhost
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
# this line is what you want to be true, else you won't get messages!
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com' # or to whatever domain your email is
authentication: "plain",
enable_starttls_auto: true,
user_name: 'my_gmail_or_other_username',
password: 'my_gmail_or_other_password'
}
Now, when you are moving towards production or even just pushing it to a public repository you obviously don't want to hardcode the username and password (for security purposes). For this I suggest you look up how to use environmental variables. The Figaro gem might also come in handy here and is another option.
This is the default 'smtp' way, there are other methods, such as the use of a gem as specified by the earlier answer.
try gem mailcatcher for development purpose.
http://mailcatcher.me/
github: https://github.com/sj26/mailcatcher
This gem will provide you a tab in browser where all your emails will be there unless you delete them.
I am trying to setup action_mailer with Rails 4.1.0 to send emails.
In my config/environments/{env}.rb, I have:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: 587,
domain: 'domain.com',
authentication: 'login',
user_name: 'email#domain.com',
password: 'pass',
enable_starttls_auto: true }
It's working fine in development, but in prod it's trying to connect to localhost.
m = Mail.new
m.delivery_method
=> #<Mail::SMTP:0xbd79fdac #settings={:address=>"localhost", :port=>25, :domain=>"localhost.localdomain", :user_name=>nil, :password=>nil, :authentication=>nil, :enable_starttls_auto=>true, :openssl_verify_mode=>nil, :ssl=>nil, :tls=>nil}>
But when I do "puts Rails.application.config.action_mailer" Im getting the correct config
{:raise_delivery_errors=>false, :default_url_options=>{:host=>"domain.com"}, :delivery_method=>:smtp, :smtp_settings=>{:address=>"smtp.mandrillapp.com", :port=>587, :domain=>"domain.com", :authentication=>"login", :user_name=>"email#domain.com", :password=>"password", :enable_starttls_auto=>true}, :assets_dir=>"xxx", :javascripts_dir=>"xxx", :stylesheets_dir=>"xxx", :asset_host=>nil, :relative_url_root=>nil}
Any idea?
The Mail gem won't use your ActionMailer config by default. ActionMailer uses Mail but those configuration settings will only apply if you send mail via ActionMailer.
If it's working in your dev mode, then you certainly have configured the Mail gem separately in your development.rb environment file, or in an environment specific initializer.
I forgot I had this config in my development.rb
Mail.defaults do
delivery_method Rails.configuration.action_mailer.delivery_method, Rails.configuration.action_mailer.smtp_settings
end
You need to add the host option for the default_url_options hash on the production.rb file, like so:
config.action_mailer.default_url_options = { :host => ENV['HOST_DEFAULT_URL'],
only_path: false }
That should do the trick.