Hello everyone,
Wishing to find a basic method to send notification emails from an OmniOSce server, I searched and finally found an easy way with Perl.
I used a Yahoo email address for this (but I assume it can be done with any other provider, as well as your own domain), along with an application password generated from the webmail space at mail.yahoo.com.
Then, I did it all in Perl.
There are many other ways to send an email, but this method is quite simple, so I thought I’d share it.
First, install the required tools:
pkg install pkg:/developer/gcc14
pkg install pkg:/system/security/kerberos-5
pkg install pkg:/service/security/kerberos-5
Export the environment variables:
export CC=/opt/gcc-14/bin/gcc
export PATH=/opt/gcc-14/bin:$PATH
Install the modules Net::SSLeay, IO::Socket::SSL, MIME::Base64, and Authen::SASL
(Press ENTER to accept the default answer for each question.)
/usr/perl5/bin/perl -MCPAN -e 'CPAN::install("Net::SSLeay")'
/usr/perl5/bin/perl -MCPAN -e 'CPAN::install("IO::Socket::SSL")'
/usr/perl5/bin/perl -MCPAN -e 'CPAN::install("MIME::Base64")'
/usr/perl5/bin/perl -MCPAN -e 'CPAN::install("Authen::SASL")'
That's it, it's done.
The server is now able to send emails.
- Now, let’s write a sample email in Perl: (mysupermail.pl)
#!/usr/perl5/bin/perl
use strict;
use warnings;
use IO::Socket::SSL;
use Net::SMTP;
use MIME::Base64;
my $smtp = Net::SMTP->new(
'smtp.mail.yahoo.com',
Port => 465,
SSL => 1,
Debug => 1
);
# Manual PLAIN authentication
my $auth_string = join("\0",
'my-yahoo-mail@yahoo.com',
'my-yahoo-mail@yahoo.com',
'your yahoo mail app password here'
);
my $encoded_auth = encode_base64($auth_string, '');
$smtp->command('AUTH', 'PLAIN', $encoded_auth)->response();
die "Authentication failed : " . $smtp->message() unless $smtp->ok();
$smtp->mail('my-yahoo-mail@yahoo.com');
$smtp->to('recipient-mail@what-you-want.com');
$smtp->data();
$smtp->datasend('From: my-yahoo-mail@yahoo.com' . "\n");
$smtp->datasend('To: recipient-mail@what-you-want.com' . "\n");
$smtp->datasend('Subject: This is a super mail !' . "\n");
$smtp->datasend("\n");
$smtp->datasend("Hello");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->datasend("I'm sending a cool mail this way !");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit();
print "Email sent !\n";