I am creating a Ruby file which allows the user to send me an email directly through my website. I have been using the gem tlsmail
and when I try my file in local everything works perfectly, I receive the emails and all the information are where they are supposed to be (like Subject, message, and so on).
This is my code:
#!/usr/bin/ruby
puts "Content-type: text/html\n\n"
require "cgi"
require "tlsmail"
cgi_request = CGI::new("html5")
contact_name = cgi_request["contact_name"]
contact_email = cgi_request["contact_email"]
contact_subject = cgi_request["subject"]
contact_message = cgi_request["contact_message"]
puts contact_name
puts contact_email
puts contact_subject
puts contact_message
msgstr = <<END_OF_MESSAGE
From: Mattia Bombelli <mattiabombelli.noreply@gmail.com>
To: A Private User <another-email@gmail.com>
Subject: Testing email
Just testing the file
END_OF_MESSAGE
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start("smtp.gmail.com", 587, "gmail.com", "mattiabombelli.noreply@gmail.com", "password", :plain) do |smtp|
smtp.send_message msgstr, "mattiabombelli.noreply@gmail.com", "another-email@gmail.com"
end
puts "Email sent!"
(The only change that I made is in the shebang, in local I am using #!/usr/local/bin/ruby
)
The problems begin when I try to put this file online into my web hosting. If I load this file into the file manager of my website, it doesn't load the tlsmail
gem and all the outputs from the html form that I am getting disappear and nothing else happens. Permissions are right and the file is in the right folder, because if I get rid of require "tlsmail"
I can see the output of all the html inputs that I am taking from another page of my website.
If I try to use instead net/smtp
I don't get any email (also the final line of my code, puts "Email sent!"
does not appear on the page, so I guess something goes wrong when I start using Net::SMTP
. I tried following this answer but I have the same problem of tlsmail
with mailfactory
. I also tried another completely different way, with mail
gem, but nothing happens.
What I don't understand is what I am doing wrong in requiring the gems for my file. How can I load online a gem and use it?