Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:28:56+00:00 2026-06-05T11:28:56+00:00

I’m having problems sending email via my Ruby code. You can see my full

  • 0

I’m having problems sending email via my Ruby code. You can see my full code on GitHub.

UPDATE: the below code has been amended to reflect suggestions from @Gaurish

UPDATE2: looks like gmail refused the login attempt – I received an email from them to warn me some unknown application tried to access my account but they disabled it

The specific class is here:

require 'net/smtp'

=begin
    http://apidock.com/ruby/v1_9_3_125/Net/SMTP/start/class
    https://devcenter.heroku.com/articles/config-vars

    I added the following config vars to Heroku
    heroku config:add GM_USR=xxxx
    heroku config:add GM_PSW=xxxx
=end

class Email
    def initialize (to, from, subject, body)
            @to = to
            @from = from
            @subject = subject
            @body = body
            @message = <<MESSAGE_CONTENT
                From: User <#{@from}>
                To: Integralist <#{@to}>
                MIME-Version: 1.0
                Content-type: text/html
                Subject: #{@subject}
                #{@body}
MESSAGE_CONTENT

            @smtp = Net::SMTP.new('smtp.gmail.com', 587)
        end

        def send_email
            @smtp.enable_starttls
            @smtp.start('furious-wind-9309.herokuapp.com', ENV['GM_USR'], ENV['GM_PSW'], :login) do |smtp|
            @smtp.send_message(@message, @from, @to)
        end
    end
end

I’m calling it like so:

email = Email.new('myemail@gmail.com', params[:email], 'test subject', params[:message]);
email.send_mail

But when I execute the code I get the error displayed on screen: 535-5.7.1 Please log in with your web browser and then try again. Learn more at

I checked the logs and I get…

2012-06-13T08:01:08+00:00 heroku[router]: POST furious-wind-9309.herokuapp.com/contact dyno=web.1 queue=0 wait=0ms service=628ms status=500 bytes=2060
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `call'
2012-06-13T08:01:08+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `block in spawn_threadpool'
2012-06-13T08:01:08+00:00 app[web.1]: 82.69.39.185 - - [13/Jun/2012 08:01:08] "POST /contact HTTP/1.1" 500 2060 0.6254

I know people will likely suggest ActionMailer or Pony, but I’d rather not use those or have those suggested to me please. I’d instead like a solution that helps fix the above code instead.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:28:59+00:00Added an answer on June 5, 2026 at 11:28 am

    [Update 1]

    If gmail doesn’t work for you, you can use SendGrid Addon which gives you upto 200emails per day at no charge.

    Here is a sample(taken from docs) on how to use their STMP API with mail gem

    require 'mail'
    Mail.defaults do
      delivery_method :smtp, { :address   => "smtp.sendgrid.net",
                               :port      => 587,
                               :domain    => "yourdomain.com",
                               :user_name => "yourusername@domain.com",
                               :password  => "yourPassword",
                               :authentication => 'plain',
                               :enable_starttls_auto => true }
    end
    
    mail = Mail.deliver do
      to 'yourRecipient@domain.com'
      from 'Your Name <name@domain.com>'
      subject 'This is the subject of your email'
      text_part do
        body 'Hello world in text'
      end
      html_part do
        content_type 'text/html; charset=UTF-8'
        body '<b>Hello world in HTML</b>'
      end
    end
    

    Using Sendgrid is much better solution because you also get access Advanced reporting & analyticss which are not available with gmail. Also, there is no restriction on “from” addresses in sendgrid.


    With Heroko, you can’t send emails directly from localhost because Heroku does not provide an outgoing mail service.

    so you will have to consider an external smtp server for sending your emails. popular ones are Gmail & Sendgrid

    this is just one trade-off of using a cloud computing platform like heroku.

    With Gmail, try doing something like this:

    require 'net/smtp'
    
        msg = "your message goes here"
        smtp = Net::SMTP.new 'smtp.gmail.com', 587
        smtp.enable_starttls
        smtp.start(YourDomain, YourAccountName, YourPassword, :login) do
          smtp.send_message(msg, FromAddress, ToAddress)
        end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.