Solved

Sending emails with inline attachments Net::SMTP

Posted on 2004-04-12
6
806 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SIMPLE Perl Regex 1 159
perl search and replace 6 168
Port 80 requests 16 96
create a gui in perl 3 88
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 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