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

Sending Attachment using MIME::Lite

Hello,

I'm a newbie to perl and i'd like some assistance trying to figure out how to send an attachment using MIME::Lite. I have searched the net far and wide and have used and modify different examples of attachment scripts. Unfortunately, i have had no luck trying to execute my script.


Every time i attempt to execute the script i receive the following response:
Global symbol "$msg" requires explicit package name at attach1.pl line 22.
Global symbol "$msg" requires explicit package name at attach1.pl line 30.
Global symbol "$msg" requires explicit package name at attach1.pl line 36.
Global symbol "$file_gif" requires explicit package name at attach1.pl line 41.
Global symbol "$msg" requires explicit package name at attach1.pl line 43.


Below is the code:

#!/usr/bin/perl -w
use strict;
use warnings;
use MIME::Lite;



### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'elliot.anico@cellularatsea.com';
my $to_address = 'elliot.anico@cellularatsea.com';


### Adjust subject and body message
my $subject = 'A message with 2 parts ...';
my $message_body = "Here's the attachment file(s) you wanted";

### Adjust the filenames
my $my_file_pdf = '/export/home/omcadmin/bin/test.pdf';
my $your_file_pdf = 'test.pdf';

### Create the multipart container
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
$msg->attach (
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";

### Add the PDF file
$msg->attach (
Type => 'pdf/pdf',
Path => $my_file_pdf,
Filename => $your_file_pdf,
Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";

$msg->send;




I know this is probably something stupid. Can someone assist me with this?
Aug 17 '09 #1
5 7744
nithinpes
410 Expert 256MB
When you are using strict pragma, all the local variables in the script need to be declared with my.
Change the line:
Expand|Select|Wrap|Line Numbers
  1. $msg = MIME::Lite->new (
  2.  
  3.  
to:

Expand|Select|Wrap|Line Numbers
  1. my $msg = MIME::Lite->new (
  2.  
  3.  

As for $file_gif, the variable is not defined anywhere in the script.
Aug 18 '09 #2
numberwhun
3,509 Expert Mod 2GB
These are all errors associated with using strict and warnings and need to be worked out to get to any real errors.

Regards,

Jeff
Aug 18 '09 #3
KevinADC
4,059 Expert 2GB
Already replied to and resolved on another forum.
Aug 18 '09 #4
I see. well, i managed to modify my script but i'm having problems attempting to send the email via Net::SMTP. I keep receiving the following error when i execute the script:

SMTP MAIL command failed:
5.7.1 Helo invalid .

at attach1.pl line 30


This is the very last line in the script below which is
$msg -> send;

Below is my modified script:

#!/usr/bin/perl -w
use warnings;
use MIME::Lite;
use Net::SMTP;


my $msg = MIME::Lite->new(
From => 'elliot.anico@cellularatsea.com',
To => 'elliot.anico@cellularatsea.com',
cc => 'wms.nmc@cellularatsea.com',
Subject => 'Multiple attachments',
Type => 'multipart/mixed');

$msg->attach( Type =>'image/jpg',
Path =>'/export/home/omcadmin/bin/Sunset.jpg',
Filename =>'Sunset.jpg');

$msg->attach( Type =>'image/jpg',
Path =>'/export/home/omcadmin/bin/Winter.jpg',
Filename =>'Winter.jpg');

$msg->attach( Type =>'TEXT',
Data =>'This is a test for outside usage');



$SMTP_SERVER = 'wmsexg01.corp.cellularatsea.com';

MIME::Lite->send('smtp', 'SMTP_SERVER');
$msg -> send;



What could i be doing wrong?
Aug 19 '09 #5
KevinADC
4,059 Expert 2GB
see perlguru
Aug 19 '09 #6

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

Similar topics

1
by: John B. Kim | last post by:
I am working on the code below: ****************************************************** use strict; use MIME::Lite; use Net::SMTP; my $from = 'steve@earthlink.net'; my @addweek1 =...
2
by: Deen | last post by:
Hi! I'm desperately seeking for a Perl script to send a message with attached documents. Thanks for help.
1
by: Zev Steinhardt | last post by:
I'm trying to use Mime::Lite to send out multipart messages. So far, it all seems to work well except for one small part. I want to display a "real name" along with the email address when I...
3
by: ramyaamar | last post by:
Hii friends I m new to perl...Just started learning....I want to know how to send an simple email in perl... I have activex perl and downloaded MIME::LITE and Mail:Mailer modules.... Can...
6
by: ssankar | last post by:
hi all - I have been tasked to send customized emails to a set of users based on a certain condition in my company. ( This is NOT SPAM ) I have used MIME::Lite successfully to send html...
2
by: idorjee | last post by:
Hi, Can anyone please tell why can't send an email with the following script. I'm using mac os x (tiger)'s terminal application. Do I need to change any configuration files? Thanks a lot in...
1
by: munisams | last post by:
Can anyone tell me Is there any python module available which functionally equivalent to Perl's MIME::Lite?? I am searching for a python MIME module which has following features: 1. Able to send...
1
by: jcor | last post by:
Hi, I'm trying to create a script that send a file in attachment of a mail: my code is something like this: #set up email my $to = "xxx\@xxxxxx.com"; my $from =...
3
by: wpflum | last post by:
I'm using Net::POP3, Email:Simple and Email::Mime to pull emails off of a server and parse them for information to see if they are the result of 'bounced' emails from our system. I then send an email...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
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?

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.