473,728 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

24 New Member
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.in\nSubject :Birthday \n\n"+"This is for demo" #Frame a mail
smtpclient.star t # start the mail process
smtpclient.send mail(the_email, 'ruby_using_smt p@webdevel.co.i n','xxxx@bksys. co.in') # send mail via ruby
smtpclient.fini sh # operation finished.
puts "Mail sent Successfully "
Jun 9 '10 #1
5 5901
improvcornartist
303 Recognized Expert Contributor
Here is an example.
Jun 9 '10 #2
littlemaster
24 New Member
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 Recognized Expert Contributor
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
littlemaster
24 New Member
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 Recognized Expert Contributor
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
1756
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 Word, or the text editor.
2
1528
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 I don't want the text box with the file path to be visible OR available. I was able to make it only 1 pixel wide and hidden, but a cursor can still occur in the box if the person clicks on the right spot. In GMAIL, you can click on the link...
1
1842
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
5729
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 with each other (You can find that post by name date10/22/2003 Time 7:22PM) I want to get the answer from Microsoft. Therefore, please answer this query only if you are from Microsoft. Thanks in advance!
14
2386
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 page. The sugegsted format are as: #1 ID : Subject : To Address: From Address...etc...
5
2672
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 that allows user go out and browse for a file? Then loads the path into a form? Jess
2
7828
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 from then have the link displayed on the form. All the files would be displayed on the computers harddrive (or a network folder) and not in the db itself. I have read and reread http://www.mvps.org/access/api/api0001.htm and understand that i...
3
3328
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" objMailer.To = "anyRecipient@456.com" objMailer.Subject = "a Subject" objMailer.Body = “I need to know ASP” on error resume next
0
2517
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 steps: 1.) Open enterprise manager. 2.) All task and then attach database.
12
6372
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
9416
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9270
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9194
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9126
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.