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

  • Home
  • SEARCH
  • 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 6782259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:43:13+00:00 2026-05-26T16:43:13+00:00

I’ve looked at all the SMTP ruby-docs and can’t figure out where I’m going

  • 0

I’ve looked at all the SMTP ruby-docs and can’t figure out where I’m going wrong:

def send(username, password, data, toAddress, fromAddress)

    smtp = Net::SMTP.new('my.smtp.host', 25)
    smtp.start('thisisunimportant', username, password, "plain") do |sender|                                                                       
        sender.send_message(data, fromAddress, toAddress)
    end

end

send(user, pass, rcpt, "Hey!")

Gives an unexpected kind of error:

/usr/lib/ruby/1.9.1/net/smtp.rb:725:in authenticate': wrong number of arguments (3 for 4) (ArgumentError)
from /usr/lib/ruby/1.9.1/net/smtp.rb:566:in
do_start’
from /usr/lib/ruby/1.9.1/net/smtp.rb:531:in start'
from gmx_pop.rb:24:in
send’
from gmx_pop.rb:30:in `’

I’ve tried kicking my computer a couple times but the problem persists.

  • 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-05-26T16:43:13+00:00Added an answer on May 26, 2026 at 4:43 pm

    Here’s a description of the Net::SMTP#start call:

    http://ruby-doc.org/stdlib-1.9.1/libdoc/net/smtp/rdoc/Net/SMTP.html#method-i-start

    the page mentions that you can just do SMTP.start to do everything at once.

    Look like you are missing the port parameter. Try port 587 for secure authentication, if that doesn’t work, port 25. (check the tutorial mentioned below)

    Your call should look like this:

    message_body = <<END_OF_EMAIL
    From: Your Name <your.name@gmail.com>
    To: Other Email <other.email@somewhere.com>
    Subject: text message
    
    This is a test message.
    END_OF_EMAIL
    
    
    server = 'smtp.gmail.com'
    mail_from_domain = 'gmail.com'
    port = 587      # or 25 - double check with your provider
    username = 'your.name@gmail.com'
    password = 'your_password'
    
    smtp = Net::SMTP.new(server, port)
    smtp.enable_starttls_auto
    smtp.start(server,username,password, :plain)
    smtp.send_message(message_body, fromAddress, toAddress)    # see note below!
    

    Important:

    • Please note that you need to add To: , From: , Subject: headers to your message_body!
    • the Message-Id: and Date: headers will be added by your SMTP server

    Check also:

    • Tutorial : http://www.java-samples.com/showtutorial.php?tutorialid=1121

    • the source code for Net::SMTP under ~/.rvm/src/ruby-1.9.1*/lib/net/smtp.rb

    • (Ruby) Getting Net::SMTP working with Gmail…?


    Another way to send emails from Ruby:

    You can use the ActionMailer gem from Rails to send emails from Ruby (without Rails).
    At first this seems like overkill, but it makes it much easier, because you don’t have to format the message body with To: , From: , Subject: , Date: , Message-Id: Headers.

    # usage:                                                                                                                                                                                               
    #   include Email                                                                                                                                                                                       
    #                                                                                                                                                                                                                                            
    # TEXT EMAIL :   
    #   send_text_email( 'sender@somewhere.com', 'sender@somewhere.com,receiver@other.com', 'test subject', 'some body text' )                                                               
    # HTML EMAIL :
    #   send_html_email( 'sender@somewhere.com', 'sender@somewhere.com,receiver@other.com', 'test subject', '<html><body><h1>some title</h1>some body text</body></html>' )                  
    
    
    require 'action_mailer'
    
    # ActionMailer::Base.sendmail_settings = {
    #   :address => "Localhost",
    #   :port => 25, 
    #   :domain => "yourdomain.com"
    # }
    
    ActionMailer::Base.smtp_settings = {        # if you're using GMail
      :address              => 'smtp.gmail.com',  
      :port                 => 587,  
      :domain               => 'gmail.com',  
      :user_name            => "your-username@gmail.com"
      :password             => "your-password"
      :authentication       => "plain",  
      :enable_starttls_auto => true  
    }
    
    class SimpleMailer < ActionMailer::Base
    
      def simple_email(the_sender, the_recepients, the_subject, the_body , contenttype = nil)
        from the_sender
        recipients the_recepients
        subject the_subject
        content_type     contenttype == 'html' ? 'text/html' : 'text/plain'
        body the_body
      end
    end
    
    # see http://guides.rails.info/action_mailer_basics.html                                                                                                                                               
    # for explanation of dynamic ActionMailer deliver_* methods.. paragraph 2.2                                                                                                                            
    
    module Email
      # call this with a message body formatted as plain text                                                                                                                                              
      #                                                                                                                                                                                                    
      def send_text_email( sender, recepients, subject, body)
        SimpleMailer.deliver_simple_email( sender , recepients , subject , body)
      end
    
      # call this with an HTML formatted message body                                                                                                                                                      
      #                                                                                                                                                                                                    
      def send_html_email( sender, recepients, subject, body)
        SimpleMailer.deliver_simple_email( sender , recepients , subject , body, 'html')
      end
    endsubject , body, 'html')
      end
    end
    

    e.g. the code above works if you want to use Gmail’s SMTP server to send email via your Gmail account.. Other SMTP servers may need other values for :port, :authentication and :enable_starttls_auto depending on the SMTP server setup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
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

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.