Solved

Sending emails with inline attachments Net::SMTP

Posted on 2004-04-12
6
803 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now