I have an excel file attachment and try to send an email. I'm able to send an email successfully, but I'm getting an error while opening the attached excel file which is given below:
error :-
"Excel cannot open the file "test.xlsx" because the file format or file extension is not valid.
Verify that the file has not been corrupted and that the file extension matches the format of the file."
Code:-
$WRKDIR="/tmp/xpyt/"
$EXCEL_FILE="test.xlsx"
$EMAIL_FROM="xxx@in.imk.com"
$EMAIL_TO="yyy@in.imk.com"
$EMAIL_SUBJECT="Excel Report"
$EMAIL_TYPE="multipart/mixed"
$msg = MIME::Lite->new(
From => $EMAIL_FROM,
To => $EMAIL_TO,
Subject => $EMAIL_SUBJECT,
Type => $EMAIL_TYPE,
);
$msg->attach(
Type => 'TEXT',
Data => "Here's the excel file you wanted"
);
chmod 0755, $EXCEL_FILE_PATH;
$msg->attach(
Type => 'application/vnd.ms-excel',
Path => $WRKDIR,
Filename => $EXCEL_FILE,
Disposition => 'attachment'
);
$msg->send();
Any help will be appreciated.