473,421 Members | 1,714 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,421 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;
  6.  
  7. my $file1 = 'c:\test1.xls';
  8. my $file2 = 'c:\sample.zip';
  9.  
  10.  
  11. my $file3 = $file2 || $file1; # file to attach
  12.  
  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.              );
  19.  
  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. }
  27.  
  28.  
  29. my $boundary = "====" . time() . "====";
  30. $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
  31.  
  32. my $message = encode_qp( $email_body );
  33.  
  34. my $len = length $$mail{body};
  35. $mail{body} = <<EOD;
  36.  
  37.  
  38. $boundary
  39. Content-Type: text/plain; charset="iso-8859-1"
  40. Content-Transfer-Encoding: quoted-printable
  41.  
  42. $message
  43. $boundary
  44.  
  45. Content-Type: application/octet-stream; name="$file3"
  46. Content-Disposition: attachment; filename="$file3"
  47. Content-Transfer-Encoding: base64
  48. Content-Length: $len
  49.  
  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
  56.  
  57. $mail{body}
  58. $boundary--
  59. END_OF_BODY
  60.  
  61.  
  62.  
  63. sendmail(%mail) or die $Mail::Sendmail::error;
  64.  
  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);
  69.  
Jul 20 '08 #1
3 5933
KevinADC
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.

http://search.cpan.org/~rjbs/MIME-Li...b/MIME/Lite.pm
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
KevinADC
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

5
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...
3
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...
6
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 =...
0
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...
1
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...
21
KevinADC
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...
17
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...
5
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...
0
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 ...
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: 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
marktang
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,...
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.