473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to attach file in an e-mail using ruby?

I have the following code, it is sending text message. I want to attach a file. How to do that?

require 'net/smtp' # plain mail
smtpclient = Net::SMTP::new( '192.168.1.1' ) # create new object to send mail
the_email="From: ruby_using_smtp@webdevel.co.in\nTo:xxxx@bksys.co.i n\nSubject:Birthday \n\n"+"This is for demo" #Frame a mail
smtpclient.start # start the mail process
smtpclient.sendmail(the_email, 'ruby_using_smtp@webdevel.co.in','xxxx@bksys.co.in ') # send mail via ruby
smtpclient.finish # operation finished.
puts "Mail sent Successfully "
Jun 9 '10 #1
5 5872
improvcornartist
303 Expert 100+
Here is an example.
Jun 9 '10 #2
It is sending mail properly with text message. It is not attach the file. In that program no syntax specified to attach mail.I have already tried this example. Any other simplest example ???
Jun 10 '10 #3
improvcornartist
303 Expert 100+
There is a section near the bottom for adding attachments.
Expand|Select|Wrap|Line Numbers
  1. filename = "/tmp/test.txt"
  2. # Read a file and encode it into base64 format
  3. filecontent = File.read(filename)
  4. encodedcontent = [filecontent].pack("m")   # base64
  5.  
  6. marker = "AUNIQUEMARKER"
  7.  
  8. ...
  9.  
  10. # Define the attachment section
  11. part3 =<<EOF
  12. Content-Type: multipart/mixed; name=\"#{filename}\"
  13. Content-Transfer-Encoding:base64
  14. Content-Disposition: attachment; filename="#{filename}"
  15.  
  16. #{encodedcontent}
  17. --#{marker}--
  18. EOF
You then need to add part3 to your email.
Jun 10 '10 #4
Could you able to understand my question?

In sendmail function, there is no option to attach file. U can configure the file attachment details properly. How will you embed this ?
Jun 11 '10 #5
improvcornartist
303 Expert 100+
The attachment is part of the email. In sendmail, you send the complete email which already has attachments added.
Jun 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RickL | last post by:
How do you attach a file to a hyperlink so that it cab be opened when clicked? I am new to .net and web development and I need to attach a file to an asp page so that when click it can be opened it...
2
by: brianwmunz | last post by:
I need to use an image instead of the normal "Browse" button for a file upload. I've seen the articles such as this one: http://www.quirksmode.org/dom/inputfile.html , but the one problem is that...
1
by: ohb | last post by:
Hello, is someone have a example of c# source of a service which is reading a attach file of an email.? Thank you. OHB.
170
by: I_AM_DON_AND_YOU? | last post by:
Whether we can upload the projects (in .zip format) in these newsgroups? I am asking this because earlier there are more than 50 posts (in one thread) about this query and they are contradicting...
14
by: Manish | last post by:
The project I am developing doesn't involves database. I want to parse the mailbox file (.mbx) and store the summary in the text file for fast retrieval and display of information in the Inbox...
5
by: Jess | last post by:
I'm trying to build a page that the user can attach a file/s to and email them thru a form. I see plenty of info on how to actually code it to send with a variable - but how do you build a form...
2
by: calebmichaud | last post by:
Hi I am having trouble understanding how to attach a file or files to a record. I want to (in form view0 allow the user to attach one or more than one file to the associated record, and then...
3
by: =?Utf-8?B?YmVueQ==?= | last post by:
See the ASP code below in order to send an email. How can I attach a file to this email please? set objMailer = Server.CreateObject("CDONTS.Newmail") objMailer.From = "anySender@123.com"...
0
by: Lexxzy | last post by:
Hi to all, I've a problem about to attach a recovered database file in the enterprise manager. My problem goes this way, I want to attach a recovered database file. So when I followed this...
12
by: qfchen | last post by:
Hi I'd like to implement in VB2005 to send a email and attech a file inside the email. Anyone knows how to do it? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.