Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
I'm seeking to be able to have a mail capability for both my droplet and my raspberry pi. I realize that there's a lot of ways to send email, but I need to have at least one of them. I have gotten closer on recent threads but not taken the ultimate step, likely because I don't understand how to configure it correctly. I've been able to do this in the past, but the dominance of giant corporations like google have altered the landscape (at least in my perception). I have to have some detente with evil corporations, but I don't like that they want everything to become proprietary and fee-promoting. I like to have alternatives, in particular, if I can roll my own.
I've had to use gmail in my sudden-onset case of becoming a secretary of something. It's a very odd calling for me, and I try to use perl to make tasks possible that would be tedious and error-prone without a script. Since then, I've been trying to get Mail::Webmail::Gmail installed on any of my 3 perl-endowed devices. Despite having made progress, cpanm keeps washing out before completion:
root@fourth:~# cpanm --verbose Mail::Webmail::Gmail cpanm (App::cpanminus) 1.7044 on perl 5.032001 built for x86_64-linux- +gnu-thread-multi ... Checking if you have Crypt::SSLeay 0.51 ... No ... ==> Found dependencies: Crypt::SSLeay Searching Crypt::SSLeay (0.51) on cpanmetadb ... --> Working on Crypt::SSLeay Fetching http://www.cpan.org/authors/id/N/NA/NANIS/Crypt-SSLeay-0.72.t +ar.gz ... OK Unpacking Crypt-SSLeay-0.72.tar.gz ... Configuring Crypt-SSLeay-0.72 ... *** THIS IS NOT AN ERROR, JUST A MESSAGE FOR YOUR INFORMATION *** Do you really need Crypt::SSLeay? Starting with version 6.02 of LWP, https support was unbundled int +o LWP::Protocol::https. This module specifies as one of its prerequi +sites IO::Socket::SSL which is automatically used by LWP::UserAgent unle +ss this preference is overridden separately. IO::Socket::SSL is a mor +e complete implementation, and, crucially, it allows hostname verification. Crypt::SSLeay does not support this. At this point, Crypt::SSLeay is maintained to support existing software that alre +ady depends on it. However, it is possible that your software does not really depend +on Crypt::SSLeay, only on the ability of LWP::UserAgent class to communicate with sites over SSL/TLS. If are using version LWP 6.02 or later, and therefore have install +ed LWP::Protocol::https and its dependencies, and do not explicitly u +se Net::SSL before loading LWP::UserAgent, or override the default so +cket class, you are probably using IO::Socket::SSL and do not really ne +ed Crypt::SSLeay. Before installing Crypt::SSLeay, you may want to try specifying a dependency on LWP::Protocol::https. root@fourth:~#
Q1) Do I really need Crypt::SSLeay? Is this a "bad logic game?"
As I read closer at DO-YOU-NEED-Crypt::SSLeay, I read this and heartbleed doesn't sound good, and superceded by LWP::Protocol::https for a reason. This sounds like a rock I should drop.
Another thing came up while I was grubbing around as root, having ssh'ed as another, which is the preferred-scheme.
I wonder what others might think of removing the back door, as it were, deleting authorized_keys in /root/.ssh/? PermitRootLogin is already set to No already wherever that counts. But if the setup was most-vulnerable where it rolled out, then erasing that access entirely seems like a proper finishing touch. (Yes, I've locked myself out of all kinds of things.)
root@fourth:~# cd .ssh/ root@fourth:~/.ssh# ll total 12 drwx------ 2 root root 4096 Jan 2 02:17 ./ drwx------ 9 root root 4096 Mar 5 04:47 ../ -rw------- 1 root root 419 Jan 2 02:17 authorized_keys root@fourth:~/.ssh#
Moving along, another way forward might be to go with something like this suggestion: Re^3: creating a secure environment for perl scripts to run. Here's my adaption of that source, with the minimal security of not having credentials in the same file:
#!/usr/bin/perl use v5.030; # strictness implied use warnings; use Email::Simple::Markdown; use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTP qw(); use Try::Tiny; use Config::Tiny; my $ini_path = qw( /home/wilma/7.values.ini ); my $sub_hash = "my_smtp"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); # -> is optional between brackets my $host = $Config->{$sub_hash}{'host'}; my $port = $Config->{$sub_hash}{'port'}; my $username = $Config->{$sub_hash}{'sasl_username'}; my $pass = $Config->{$sub_hash}{'sasl_password'}; my $ssl = $Config->{$sub_hash}{'ssl'}; say "values are $host $port $username $ssl"; my $output = "Come here, Mr. Watson"; my $message = Email::Simple::Markdown->create( header => [ Subject => "Report", To => 'tallharry84@gmail.com', From => 'noreply@foo.com' ], body => $output ); try { sendmail( $message, { from => 'noreply@foo.com', transport => Email::Sender::Transport::SMTP->new( { host => $host, port => $port, sasl_username => $username, sasl_password => $pass, ssl => $ssl, } ) } ); } catch { warn "sending failed: $_"; }; __END__ wilma@fourth:~$
On execution, I'm unable to create the smtp connection:
wilma@fourth:~$ ./1.smtp.pl values are fourth 465 wilma starttls sending failed: unable to establish SMTP connection to (fourth) port 4 +65
So what values are not working here? I don't know, and it could be more than one of them. I think I get the hostname right:
wilma@fourth:~$ hostname fourth
I chose port 465 because that was what the module would default too. (Completely grasping at straws.)
Furthermore, I chose the username to be the actual name of an existing user on this machine. Does it have to be one? What I really don't like about this scheme is that the only password this user knows is also the one that would elevate her to root, and it's sitting there in a plain text file. This seems wildly wrong from a security vantage point.
While I'd like to get this straightened out, there is at least a third possibility for email on a server, which is to follow haukex's guide for rpi setup, section 5:
sudo apt-get install alpine postfix bsd-mailx sudo vi /etc/postfix/main.cf #=> correct "myhostname" if necessary #=> if it doesn't exist, add the line "smtp_tls_security_level = may" #=> if this option or the option "smtp_tls_CApath" doesn't exist, # add the line "smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt +" sudo dpkg-reconfigure postfix # and configure as appropriate echo "root: pi" | sudo tee -a /etc/aliases && echo "---" && cat /etc/a +liases sudo newaliases && sudo systemctl restart postfix echo "This is a mailx test" | mailx -s "mailx test" root alpine # Configure "User Domain" and anything else as needed
So, how do I best get email working on this server?
|
|---|