Forum Moderators: phranque
open (MAIL, "|/usr/sbin/sendmail -t") || die "Can't open /usr/sbin/sendmail\n";
print MAIL "To: $to\n";
print MAIL "From: $from ($title)\n";
print MAIL "Subject: $title User Information\n\n";
print MAIL $body;
close (MAIL); $from="realaccount@example.com"; [edited by: keyplyr at 5:13 am (utc) on Jul 11, 2017]
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP();
use Email::Simple ();
use Email::Simple::Creator();
my $transport = Email::Sender::Transport::SMTP->new({
host => 'mail.example.com',
port => 25,
sasl_username => 'username',
sasl_password => 'password',
});
my $email = Email::Simple->create(
header => [
To => $to,
From => "$from ($title)",
Subject => "$title User Information",
],
body => $body,
);
sendmail($email, { transport => $transport });
use MIME::Lite;
use Net::SMTPS;
my $msg = MIME::Lite ->new (
From => "$from ($title)",
To => $to,
Subject => "$title User Information",
Data => $body,
Type => 'text/html'
);
my $smtps = Net::SMTPS->new(
'mail.example.com',
Port => 467, # I'm guessing for SSL, instead of port 25
doSSL => 'starttls',
SSL_version=>'TLSv1'
);
$smtps->auth ('username', 'password') or die("Could not authenticate with mail.example.com.\n");
$smtps->mail($from);
$smtps->to($to);
$smtps->data();
$smtps->datasend($msg->as_string());
$smtps->dataend();
$smtps->quit;
use Net::SMTP;
use strict;
use warnings;
# Assign $from, $to, and $title
# blah blah blah
# Send email
my $smtp = Net::SMTP->new(
"mail.example.com",
Hello => 'mail.example.com', # not sure if this is right, the docs were pretty vague
Timeout => 30,
Debug => 1, # for testing only
Port => 465,
SSL => 1
) or die "Couldn't connect to SMTP server";
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend("From: $from ($title)\n");
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: $title User Information\n");
$smtp->datasend("\n");
$smtp->datasend(qq~
Test message
~);
$smtp->dataend();
$smtp->quit;