Skip to content

Instantly share code, notes, and snippets.

@battila
Created August 7, 2013 22:10
Show Gist options
  • Save battila/6179271 to your computer and use it in GitHub Desktop.
Save battila/6179271 to your computer and use it in GitHub Desktop.
Sending html e-mail with attachment
#!/usr/bin/perl -w
use warnings;
use strict;
use MIME::Lite;
use MIME::Base64;
use File::Slurp;
use Encode;
my $MyAttachment = 'attachment.bin';
my $to_email = '[email protected]';
my $from_email = '[email protected]';
my $html_msg = decode_utf8(read_file('html_email.html')) ;
my $msg = MIME::Lite->new (
Subject => "HTML email test",
From => $from_email,
To => $to_email,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
$msg->attach (
Type => 'text/html',
Data => $html_msg
) or die "Error adding the html message part: $!\n";
$msg->attach (
Type => 'text/plain',
Path => $MyAttachment,
Filename => $MyAttachment,
Disposition => 'attachment'
) or die "Error adding $MyAttachment: $!\n";
$msg->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment