1

I am sending an email via SMTP in perl . The email contains some tables,links and lists. I am using html format data.

$smtp->data();
$smtp->datasend("MIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n<H1>");
$smtp->datasend("$message");
...
$smtp->dataend();
$smtp->quit;

Sometimes the email size is too large around 1mb. Is there any way I can reduce the size of email without reducing the amount of data.I do not want the message as an attachment. I use outlook to open the mails.

Sagar D
  • 188
  • 1
  • 12
  • I compressed it using gzip but problem is how to send it to outlook so that it displays it correctly. – Sagar D Feb 13 '13 at 02:22
  • Outlook could be smart enough to display it inline. Many MUAs will display a gziped text file inline. – jordanm Feb 13 '13 at 02:24

1 Answers1

0

You should use Mail::Sender for sending attachments through email

#!/usr/bin/perl
use Mail::Sender

$to = 'email1@example1.com,email2@example2.com';
$sender =new Mail::Sender {
        smtp => 'smtp.mailserver.com',
        from => 'script@somedomain.com,
        });

$subject = 'This is a Test Email';
$sender->OpenMultipart({
        to      => "$to",
        subject => "$subject",
        });

$sender->Body;
$sender->SendLineEnc("Test line 1");
$sender->SendLineEnc("Test line 2");

$sender->Attach({
        description     => 'Test file',
        ctype           => 'application/x-zip-encoded',
        encoding        => 'Base64',
        disposition     => 'attachment;
        filename="File.zip"; type="ZIP archive"',
        file            => "$file",
        });

$sender->Close();
exit();

or using MIME::Lite

use MIME::Lite;

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

### Add the ZIP file
$msg->attach (
   Type => 'application/zip',
   Path => $my_file_zip,
   Filename => $your_file_zip,
   Disposition => 'attachment'
) or die "Error adding $file_zip: $!\n";

### Send the Message
$msg->send('smtp', $mail_host, Timeout=>60);
  • Thanks for the answers.I just modified some data to reduce the size. – Sagar D Feb 14 '13 at 21:50
  • ok. But did you tried above solution? Does it work? Because I haven't tried that. –  Feb 15 '13 at 05:30
  • I did not try that as I did not want it to be a attachment.But attachments works with smtp as well,I used it earlier in one of my code. – Sagar D Feb 19 '13 at 01:10
  • Yes text attachments works with smtp. But for zip files or binary file attachments I think you need above modules. –  Feb 19 '13 at 03:54
  • Can you please update your question mentioning that you don't want it as attachments. –  Feb 19 '13 at 03:56