473,395 Members | 1,521 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,395 software developers and data experts.

Attaching 2 files to email using perl sendmail

I am having an issue with attaching 2 attachments one xip and other excel file with email and sending using perl sendmail. I tried to look on various forums and everywhere i get advice using MIME :: Lite. Unfortunately i cannot use it . I have tried to write a program on my own to send 2 attachments and sending using perl sendmail but program is not working. It is reading only first file for attachment purposes and ignores second one.I would appreciate if anyone can pinpoint error with my program.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use Mail::Sendmail;
  4. use MIME::QuotedPrint;
  5. use MIME::Base64;
  7. my $file1 = 'c:\test1.xls';
  8. my $file2 = 'c:\sample.zip';
  11. my $file3 = $file2 || $file1; # file to attach
  13. my %mail = ( To   => "abc@yahoo.com",
  14.               From    => "def@yahoo.com",
  15.               Cc      => "hij@yahoo.com",
  16.               Subject => "Two Attachments",
  17.               smtp    => 'mac.abc.com'
  18.              );
  20. my $content;
  21. { local $/ = undef; # slurp file
  22. open IN, $file3 or die "Error opening $file3: $!";
  23. binmode IN; $content = <IN>; 
  24. $mail{body} += encode_base64(<IN>);
  25. close IN;
  26. }
  29. my $boundary = "====" . time() . "====";
  30. $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
  32. my $message = encode_qp( $email_body );
  34. my $len = length $$mail{body};
  35. $mail{body} = <<EOD;
  38. $boundary
  39. Content-Type: text/plain; charset="iso-8859-1"
  40. Content-Transfer-Encoding: quoted-printable
  42. $message
  43. $boundary
  45. Content-Type: application/octet-stream; name="$file3"
  46. Content-Disposition: attachment; filename="$file3"
  47. Content-Transfer-Encoding: base64
  48. Content-Length: $len
  50. $mail{body}
  51. --$boundary
  52. Content-Type: application/vnd.ms-excel; name="$file3"
  53. Content-Disposition: attachment; filename="$file3"
  54. Content-Transfer-Encoding: base64
  55. Content-Length: $len
  57. $mail{body}
  58. $boundary--
  63. sendmail(%mail) or die $Mail::Sendmail::error;
  65. open(OUT, ">>$sendmail_log") or die "Cannot open LOG file $file3: $!";
  66. print OUT $Mail::Sendmail::log;
  67. print OUT "\n==============================================================================\n";
  68. close(OUT);
Jul 20 '08 #1
3 5930
4,059 Expert 2GB
Instead of trying to debug your code I am going to suggest you use the MIME::Lite module to send the email, it will make adding attachments to your emails a simple process.

Jul 20 '08 #2
thanks Kevin but unfortunately i cannot use mime lite. we are doing development on windows server and it does not have mime lite module. we cannot install due to permission issue.
Jul 20 '08 #3
4,059 Expert 2GB
see perlguru forum.
Jul 20 '08 #4

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

Similar topics

by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Suppose you want to spam your friend, and you have lots of # friends. The solution is to write a program to do it. After a gander # at python docs, one easily...
by: David P. Jessup | last post by:
Good day to all. I have found out my webhost doesn't support CDO or CDONTS(Sun ONE Active Server Pages with SpikePack unavailable). So, my question, is it possible to write an ASP page to call...
by: atinti | last post by:
I'm tyring to write something that will send a simple email using Perl so far this is what I have #!/usr/bin/perl -w use strict; my $executable = "saplotus.exe'; my $server =...
by: cgipro2007 | last post by:
Hello I have a perl script that sends an email letter (using sendmail program) to some number of email addresses. However, this mailing list is a little bit long (10,000+ emails) When the...
by: Kesavan | last post by:
I install apache2 in /usr/local/apache2 and install php5 by ./configure --with-apxs2=/usr/local/apache2/bin/ apxs PHP is successfully installed in my system. But now my .php files inside...
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
by: patelxxx | last post by:
I'm testing out an .cgi example to send an email, however I'm not sure where the sendmail program lives on my Windows o/s. The example states that I need to figure out where sendmail program lives...
by: simononestop | last post by:
Hi im totally new to perl this is my first go at using it (I normally use asp). I have set up a form with a cgi script from demon hosting. I have edited the script and the form works it sends me an...
by: gervo | last post by:
I have built a series of email forms in flash MX. using perl. the forms work for some people but not all and I was hoping some one could help me out. Here is the Actionscript on the send button ...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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: 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...

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.