VMware Cloud Community
karo9pare
Contributor
Contributor

Mail

Hi,

I am using the script below to send a mail.

How can I attach a file? And I don't want to install anything on my server.

Or maybe there is another way to do this without the scrip below...

Thank you.

use Net::SMTP;

die ("Usage: sendmail.pl <smtpserver> <from> <to> <subject> <msgfilename>") if ($#ARGV != 4);

$smtpserver = $ARGV[0];

$sender = $ARGV[1];

$recipient = $ARGV[2];

$subject = $ARGV[3];

$msgfilename = $ARGV[4];

$smtp = Net::SMTP->new($smtpserver);

$smtp->mail($sender);

$smtp->to($recipient);

$smtp->data();

$smtp->datasend("Subject: $subject\n");

$smtp->datasend("To: $recipient\n");

$smtp->datasend("\n");

open (MESSAGE, $msgfilename) || die "cannot open message file $msgfilename.";

@nachricht=<MESSAGE>;

close MESSAGE;

foreach $zeile (@nachricht) {

$smtp->datasend("$zeile");

}

$smtp->dataend();

$smtp->quit;

Reply
0 Kudos
2 Replies
kjb007
Immortal
Immortal

You can attach using the module you're using.

$smtp->datasend("MIME-Version: 1.0\n");

$smtp->datasend("Content-Disposition: attachment; filename=\"/a/path/to/file.txt\"\n");

$smtp->datasend("Content-Type: application/text; name= attachment.txt ");

$smtp->datasend();

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
Reply
0 Kudos
azn2kew
Champion
Champion

Here is a short guide how to send html mail via service console.

If you found this information useful, please consider awarding points for "Correct" or "Helpful". Thanks!!!

Regards,

Stefan Nguyen

iGeek Systems LLC.

VMware, Citrix, Microsoft Consultant

If you found this information useful, please consider awarding points for "Correct" or "Helpful". Thanks!!! Regards, Stefan Nguyen VMware vExpert 2009 iGeek Systems Inc. VMware vExpert, VCP 3 & 4, VSP, VTSP, CCA, CCEA, CCNA, MCSA, EMCSE, EMCISA
Reply
0 Kudos