473,750 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching 2 files to email using perl sendmail

2 New Member
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 5953
KevinADC
4,059 Recognized Expert Specialist
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
zaxxon25
2 New Member
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 Recognized Expert Specialist
see perlguru forum.
Jul 20 '08 #4

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

Similar topics

5
1719
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 found the module for the job. # see http://python.org/doc/2.3.4/lib/SMTP-example.html # the code is a bit long with the command line, but the key lies at # the bottom four lines. The gist is this:
3
4973
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 their sendmail to sent email? Or will I have to do some quick learning on cgi? Thanks for any input.
6
10554
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 = 'test@domain'; my $from = 'aetinti@gmail.com';
0
1245
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 script starts, it goes smoothly, however the more the time passes the script starts to slow down more and more. I guess this is because a lot of emails are invalid and therefore they are kept in the mail queue location of the server (my server is UNIX). ...
1
5830
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 /usr/local/apache2/htdocs doesn't get phrased. When I run suse-10-2:/home/kesavan # php info.php
21
34432
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
17
2954
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 on my system, how do I this? Please see part of the code below: $mailprog = '/usr/sbin/sendmail'; open (MAIL, "|$mailprog -t) I know using sendmail.pm / use sendmail module is easier however I would like to try this example out without...
5
2306
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 email. however all the information is missing form the email I only get the first form text field?? #!/bin/perl # ------------------------------------------------------------
0
2034
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 on (release, keyPress "<Enter>") { if (company ne "" and first ne "" and last ne "" and phone ne "" and fax ne "" and mobile ne "" and email ne "" and address ne "" and city ne "" and state ne "" and zip ne "") { i = "0"; validmail = 0;...
0
8839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
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
9397
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...
0
9257
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
8264
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
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
4893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.