Solved

Sending emails with inline attachments Net::SMTP

Posted on 2004-04-12
6
821 Views
Last Modified: 2008-03-17
I need a method to send an email with attachment in Perl without using Mime::Lite.  Every example on the Web that I have found uses Mime:Lite to email attachments, but my installation of ActiveState Perl will not support Mime:Lite.

Can anyone show me a basic method to email attachments using Mime:Lite that would be compatible with ActiveState Perl 5.8?

Thanks!
0
Comment
Question by:gmahler5th
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 10809651
Why do you think ActiveState Perl won't support MIME::Lite?    Of course it will.  MIME::Lite is one of the easiest modules to install.  It consists of a single file which you can place anywhere on your server.

0
 

Author Comment

by:gmahler5th
ID: 10814659
It's currently not installed.  
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10818636
Then just install it.

With ActiveState Perl, you can just do

ppm install MIME::Lite

That's all there is to it.  Easy.

You can even install it manually if you really want to.  It's just as easy.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gmahler5th
ID: 10826301
Okay, now I'm using Mime:Lite (finally got it installed...)  I'm receiving the email correctly, but it's not sending with an actual attachment.  It is sending in base64.  How can I make the script send an actual attachment?  (Code below)

----------------------
#! e:\perl\bin
use CGI qw(:standard);            
print header();


use MIME::Lite;
use Net::SMTP;


my $from_address = 'steve@stevetout.com';
my $to_address = 'sujit.ravindranath@attws.com';
my $subject = 'MIME Net::SMTP test';
my $mime_type = 'TEXT';
my $message = "Hello world!\n";

# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
   From => $from_address,
   To   => $to_address,
   Subject => $subject,
   Type => $mime_type,
   Data => $message
   )
  or die "Error creating MIME body: $!\n";

my $filename = 'e:\inetpub\wwwroot\sso\upload\test.zip';
my $recommended_filename = 'better_filename.zip';

# Attach the test file
$mime_msg->attach(
   Type => 'application/zip',
   Path => $filename,
   Filename => $recommended_filename
   )
  or die "Error attaching test file: $!\n";

my $message_body = $mime_msg->body_as_string();


# Set this variable to your smtp server name
my $ServerName = "nwestmail.entp.attws.com";

# Create a new SMTP object
$smtp = Net::SMTP->new($ServerName) or
   die "Couldn't connect to server";

$smtp->mail( $from_address );
$smtp->to( $to_address );

$smtp->data();
$smtp->datasend($message_body);
$smtp->dataend();

# Close the connection
$smtp->quit();  

----------------------
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10828789
No need to manually do the SMTP stuff yourself with MIME::Lite.  The problem is that you are missing the essential headers as you are just using the mail body.

Change your script to:

#! e:\perl\bin
use strict;
use CGI qw(:standard);  
use MIME::Lite;
         
print header;

my $from_address = 'steve@stevetout.com';
my $to_address = 'sujit.ravindranath@attws.com';
my $subject = 'MIME Net::SMTP test';
my $mime_type = 'TEXT';
my $message = "Hello world!\n";

# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
   From => $from_address,
   To   => $to_address,
   Subject => $subject,
   Type => $mime_type,
   Data => $message
   )
  or die "Error creating MIME body: $!\n";

my $filename = 'e:\inetpub\wwwroot\sso\upload\test.zip';
my $recommended_filename = 'better_filename.zip';

# Attach the test file
$mime_msg->attach(
   Type => 'application/zip',
   Path => $filename,
   Filename => $recommended_filename
   )
  or die "Error attaching test file: $!\n";

MIME::Lite->send('smtp', "nwestmail.entp.attws.com", Timeout=>60);

$mime_msg->send or die "Problems sending mail $!\n";

0
 

Expert Comment

by:billfinkri
ID: 14536657
TinTin - Thanks!

What a wonderful example - and EASY to follow!

I wasn't even looking for a solution to this sort of problem, stumbled arcoss this thread - and this came in VERY handy!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question