Reputation: 77
My script sends email to a user with an attachment file.
The file name is hello.txt.
It contains "HELLO WORLD!! :D".
When I send the email, the file hello.txt is attached with the email. But, when I open the file, hello.txt is blank and empty. It should contain "HELLO WORLD!! :D"
The CODE
#!/usr/bin/perl
use MIME::Lite;
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc => $cc,
Subject => $subject,
Type => 'multipart/mixed' #I SUSPECT, THE PROBLEM AT HERE
);
# Add your text message.
$msg->attach(
Type => 'text',
Data => $message
);
# Specify your file as attachement.
$msg->attach(Type => 'application/text', #I SUSPECT, THE PROBLEM AT HERE
Path => 'C:\Users\Desktop',
Filename => 'hello.txt',
Disposition => 'attachment'
);
$msg->send;
print "Email Sent Successfully\n";
Should I change Type
or application/text
?
Upvotes: 0
Views: 115
Reputation: 123471
Path => 'C:\Users\Desktop',
Path should be the path name of the file on your system. What you gave is only the directory name, where the file is located. Trying to read this will result in empty data - and thus empty content for the attached file. Instead you need to use
Path => 'C:\Users\Desktop\hello.txt',
Upvotes: 2