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 7685773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:19:41+00:00 2026-05-31T19:19:41+00:00

I’m using Ruby script and the mail gem to send emails. Question – How

  • 0

I’m using Ruby script and the “mail” gem to send emails.

Question – How could how to send a graph via email in Ruby without saving to disk? Is this possible? Which graphing tool would you recommend and would the “mail” gem support somehow streaming this out? (or it it a given you have to save to disk first) If it’s possible/easy sample code lines should how to would be great….

  • 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-31T19:19:42+00:00Added an answer on May 31, 2026 at 7:19 pm

    Your complete answer.

    This uses a pure Ruby PNG graph for simplicity; a real world app would likely use SVG, or fast native code, or a graph API.

    #!/usr/bin/env ruby
    =begin
    
    How to send a graph via email in Ruby without saving to disk
    Example code by Joel Parker Henderson at SixArm, joel@sixarm.com
    
        http://stackoverflow.com/questions/9779565
    
    You need two gems:
    
        gem install chunky_png
        gem install mail
    
    Documentation:
    
        http://rdoc.info/gems/chunky_png/frames
        https://github.com/mikel/mail
    
    =end
    
    
    # Create a simple PNG image from scratch with an x-axis and y-axis.
    # We use ChunkyPNG because it's pure Ruby and easy to write results;
    # a real-world app would more likely use an SVG library or graph API.
    
    require 'chunky_png'
    png = ChunkyPNG::Image.new(100, 100, ChunkyPNG::Color::WHITE)
    png.line(0, 50, 100, 50, ChunkyPNG::Color::BLACK)  # x-axis
    png.line(50, 0, 50, 100, ChunkyPNG::Color::BLACK)  # y-axis
    
    # We do IO to a String in memory, rather than to a File on disk.
    # Ruby does this by using the StringIO class which akin to a stream.
    # For more on using a string as a file in Ruby, see this blog post:
    # http://macdevelopertips.com/ruby/using-a-string-as-a-file-in-ruby.html
    
    io = StringIO.new
    png.write(io) 
    io.rewind
    
    # Create a mail message using the Ruby mail gem as usual. 
    # We create it item by item; you may prefer to create it in a block.
    
    require 'mail'
    mail = Mail.new
    mail.to = 'alice@example.com'
    mail.from = 'bob@example.com'
    mail.subject = 'Hello World'
    
    # Attach the PNG graph, set the correct mime type, and read from the StringIO
    
    mail.attachments['graph.png'] = {
      :mime_type => 'image/png', 
      :content => io.read 
    }
    
    # Send mail as usual. We choose sendmail because it bypasses the OpenSSL error.
    mail.delivery_method :sendmail
    mail.deliver
    
    • 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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.