sending mail in rails 2.3.8 - ruby-on-rails

I am using rails 2.3.8. I am trying to send mail through action mailer. When i call the mailer function it does not throw any error and completes successfully even the log shows that the mail is sent. But when i check the mail box there is not mail sent actually Is there any problem with sendmail configuration or something else. Please help me out with it.
Thanks
Here are my setting in development.rb
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
:location => "path/to/sendmail",
:arguments => "-i"
}

if
config.action_mailer.perform_deliveries = true
dont work
maybe a sendmail misconfiguration , try to send a mail from bash and check the output
touch file.log;
cat - file.log << EOF | sendmail -t
to:email#address.com
from:you#address.com
subject:Testing 123
TEST
EOF
otherwise
I find useful to use this program (a fake smtp server) to test outgoing mail
http://www.aboutmyip.com/AboutMyXApp/DevNullSmtp.jsp

add this to your development.rb file
config.action_mailer.perform_deliveries = true
because i don't see it in your configuration

Related

「rescue500 => SocketError : getaddrinfo: Name or service not known」 cannot be resolved

Want to achieve
ruby 2.6.5
Rails 6.0.4
Amazon AWS S3
Thankyou for watching.
I am creating an application in Rails.
I want to upload an image to AWS S3, but I get the following error in the log and cannot upload it
rescue500 => SocketError : getaddrinfo: Name or service not known
/home/ec2-user/test_app/web/app/services/clamav_service.rb:4:in `initialize'
config/environments/production.rb
config.x.s3.local = false
config.x.s3.region = ENV["AWS_S3_REGION"]
config.x.s3.bucket = ENV["AWS_S3_BUCKET"]
config.x.s3.access_key = ENV["AWS_S3_ACCESS_KEY"]
config.x.s3.secret_access_key = ENV["AWS_S3_SECRET_ACCESS_KEY"]
config.x.s3.password = ENV["AWS_S3_PASSWORD"]
config.x.s3.path = ENV["AWS_S3_PATH"]
Environment variables in ec2
AWS_S3_REGION=ap-northeast-1
AWS_S3_BUCKET=xxx
AWS_S3_ACCESS_KEY=yyy
AWS_S3_SECRET_ACCESS_KEY=zzz
AWS_S3_PASSWORD=
AWS_S3_PATH=uploads/
We have made the following settings.
I have confirmed that AWS_S3_ACCESS_KEY and AWS_S3_SECRET_ACCESS_KEY are correct.
In my local environment, I was able to upload successfully, so I think it is a bug in my environment.
I would appreciate it if you could tell me if I missed anything.
clamd doesn't expand environment variables, so I had to write them directly.

AactionMailer configuration without authentication

I have to send e-mails from a Rails application, and am trying to do so with ActionMailer. The mail administrator created a new account for the purpose that requires no authentication; I am able to send messages with this new account with msmtp using a configuration like (in ~/.msmtprc)
account myapp
auth off
host mailserver.domain
port 25
from myapp#domain
user myapp#domain
password
In the development.rb file I introduced a similar configuration:
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'mailserver.domain',
from: 'myapp#domain',
port: 25,
domain: 'domain',
authentication: 'off',
user_name: 'myapp#domain',
password: '',
enable_starttls_auto: false }
config.action_mailer.perform_deliveries = true
But whenever a mailing method is invoked I get the following exception:
(0.7ms) ROLLBACK
Completed 500 Internal Server Error in 387ms
Errno::ECONNREFUSED (Connection refused - connect(2)):
app/models/user.rb:28:in `send_admin_mail'
app/controllers/registrations_controller.rb:15:in `create'
I imagine something is wrong or missing in the development.rb file, but I have no idea what it may be. Any help is appreciated.
Update: Following eugen's suggestion below I found that at execution time ActionMailer::Base.smtp_settings does not contain the correct settings; in particular, address is pointing to localhost instead of pointing to the mail server:
=> "{:address=>\"localhost\",
:port=>25,
:domain=>\"localhost.localdomain\",
:user_name=>nil,
:password=>nil,
:authentication=>nil,
:enable_starttls_auto=>true}"
How can I correct this?
Actually, your configuration has some problems. Just like the the 'from:' key, it should not be placed in smtp_settings. As for other possible problems, please refer RubyonRails.guides
Hope to do some help.

Sending mail using Mandrill smtp on rails app

I'm hosting a rails app on my own server using Unicorn and Nginx. I have an issue when i try to send mails using mandrill, i get the following error :
Net::SMTPServerBusy: 401 Syntax: HELO hostname
And this is my configuration on production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default charset: 'utf-8'
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: 587,
authentication: "plain",
domain: localhost,
enable_starttls_auto: true,
user_name: ENV['MANDRILL_USERNAME'],
password: ENV['MANDRILL_API_KEY']
}
what i get from the error is that maybe mandrill reject the domain because is not "safe/registered"??
I already tried changing the domain to 'timewarp.us' (yet not registered), and i'm having the same problem.
If i change madrill and use the gmail smtp it works as expected.
This is the first time i'm doing a deploy to a server and i'm kinda lost.
Any help would be great. Thanks!
Try adding your actual domain instead of localhost. My guess is that Mandrill won't accept localhost as a hostname.

Sendmail working in Linux Terminal, not in Rails 3

I'm running Ubuntu 10.04 with Rails 3.2.2.
I just installed and configured sendmail. When mail is sent through terminal it worked perfectly.
But when i try to call it through Rails, no success.
Although it doesn't really looks like it's failing though. I get no errors, and see this in my console:
#<Mail::Message:40338240, Multipart: false, Headers: <From: alert#email.com>, <To: chris#email.com>, <Subject: Hi chris, a testmail too you!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <importance: High>, <X-Priority: 1>>
I am in development have the following settings in my development.rb:
config.action_mailer.delivery_method = :sendmail
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
I have setup an actionmailer, with the corresponding alert_mail.html.erb:
class UserMailer < ActionMailer::Base
default from: "alert#email.com"
def alert_mail(site)
#site = site
#user = site.user
#url = "http://example.com/login"
mail(:to => #user.email_address, :subject => "Hi chris, a testmail too you!", :importance => "High", 'X-Priority' => '1')
end
end
And this is what I call:
UserMailer.alert_mail(site)
Could it be something with permissions?
Things i've tried
- Tried running in production mode
- chmod'd the sendmail executables to 777
- Tried removing the priority settings
- Running it with rails server instead of nginx
I hope someone can help me, thanks in advance!
(email.com is just a replacement, i use a valid domain)
EDIT:
sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. But it still doesn't work when it is supposed to, through my browser. Strange thing is, this seems to be happening in nginx only. When I stop nginx, and start rails server, then it works. But when I when nginx is the server, it doesnt send any mail.
I think you need to call
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. It fixes the problem that I was calling the function wrong. But it was still not sending email for me. After a while i manage to get it working.
One of the things I found out is that there was actually another mail log which I did oversee:
/var/log/mail.log.1
It showed me the following error:
sendmail[4453]: NOQUEUE: SYSERR(nobody): can not chdir(/var/spool/mqueue-client/): Permission denied
I used ls -ld /var/spool/mqueue-client/ to see that the directory is restricted by the smmsp group:
drwxrws--- 2 smmsp smmsp 4096 2013-01-12 17:51 /var/spool/mqueue-client/
So I added the nobody user (from the error SYSERR(nobody)) to the smmsp group:
usermod -a -G smmsp nobody
I tested again, and it doesn't work yet. After checking the log I got the same error. To be sure I rebooted my server and now the error message changed a little bit:
NOQUEUE: SYSERR(nobody): can not write to queue directory /var/spool/mqueue-client/ (RunAsGid=65534, required=115): Permission denied
After searching and trying useless stuff for a while i decide to change the primary group of nobody to 115 (smmsp) the /etc/psswd file and saw the following settings:
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
to
nobody:x:65534:115:nobody:/nonexistent:/bin/sh
This solved my problem and it's sending mails now. I understand that this is not the best solution, but I don't really know how else I would give nobody access, since it's requiring the specific GID. I hope someone else here does.

reset password on production with use the devise, unicorn

If I try to reset password I see: We're sorry, but something went wrong.
Then I see to my logs:
poruction.log
Sent mail to achempion#gmail.com (238ms)
Completed 500 Internal Server Error in 610ms
OpenSSL::SSL::SSLError (hostname does not match the server certificate):
In my production.rb I set the config.action_mailer.default_url_options = { :host => '178.79.153.194' }
and openssl version is OpenSSL 1.0.0g 18 Jan 2012
I reset password via devise gem
It was my mistake. I forgot to configure ActionMailer.
link tutorial

Resources