- LocalLib.git
- Email.pm
This file ( 2kB ) exceeds the allowed full mode (48 kb) size.
The editor full hight is disabled, only scrolling is allowed..
If you wish to edit a file, it is recommended to use the scroll mode as some users do not like the full height
mode, although some users like it.
package Local::Email;
# this works, but replaced with Local::SendGrid
use v5.26;
use Email::Stuffer;
use Data::Printer;
use Try::Tiny;
use IO::All;
my $api_key = io('/home/raj/.local/sendgrid_api_key')->slurp
|| die 'no api key'; # say $api_key;
# default e-mail to/from (requires separate 'chomp' - wtf???):
my $self_addr = io('/home/raj/.local/email_address')->slurp
|| die 'no default email addess'; chomp($self_addr); # say $self_addr; exit;
my $username = 'apikey';
my $password = $api_key;
my $host = 'smtp.sendgrid.net';
my $port = 587;
my %transport = (
sasl_username => $username,
sasl_password => $password,
host => $host,
port => $port, # automatically picked up from ssl/starttls/none
debug => 0, # maybe over-ridden in plain_text()
starttls => 1,
ssl => 0,
);
sub plain_text {
my $args = shift;
$transport{debug} = $args->{debug};
my $email = Email::Stuffer
->to($args->{recipient} || $self_addr)
->from($args->{sender} || $self_addr)
->subject($args->{subject})
->text_body($args->{message})
->transport(SMTP => \%transport); # p $email;
try { $email->send_or_die } # uses Email::Sender::Simple (localhost/25 default)
catch { # warn $_;
# capture all before stack trace (Email::Sender::Failure object):
if ( my ($msg) = $_ =~ /(.*)Trace begun/s ) { # warn $msg;
chomp $msg; # remove empty line
die "Local::Email::send() failed: $msg";
}
}
}
sub email_file { } # see RWGPS::Mail for details
1;