SMTP Wrapper for Mutt E-Mail Client will allow you to send mails from Mutt directly using an SMTP server.
In most networks the administrators does not allow individual machines to run an SMTP server, such as Sendmail or QMail. Since Mutt only works through the local Sendmail program, in those networks, it makes impossible to send e-mails. This small wrapper allows you to use Mutt with an SMTP server. This PERL program accepts the same command set as Sendmail but it then delivers the mails through SMTP.
Installation:
- Copy the PERL code below, and save it under name mutt-smtp-wrapper.pl
- Change its mode to executable (chmod 755 mutt-smtp-wrapper.pl)
Add the following line into your ~/.muttrc file:
set sendmail=/usr/bin/mutt-smtp-wrapper.pl
This will make Mutt to use our wrapper instread of Sendmail while sending mails.
Here is the source code for mutt-smtp-wrapper.pl.
#!/usr/bin/perl
#
# @(#)mutt-smtp-wrapper.pl1.2 05/05/01
#
# Copyright (c) 2004
# Ali Onur Cinar &060;cinar(a)zdo.com&062;
#
# License:
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial use and without fee is hereby granted
# provided that the above copyright notice appear in all copies and that
# both the copyright notice and this permission notice and warranty
# disclaimer appear in supporting documentation, and that the name of
# Ali Onur Cinar not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior permission.
#
#
# Usage:
#
# Please update the following parameters according to targeted SMTP server:
#
# Put the name of your SMTP server
#
$server = "mail.domain.name";
#
# Put the address that will be used while sending trough this SMTP server
# (you can still put whatever email you prefere in your From: line)
#
$from = "user\@domain.name";
#
# Turn the debugging on/off (0=off, 1=on)
#
$debug = 0;
#
# SASL Authentication (if required)
#
#$username = "";
#$password = "";
#
use Net::SMTP; # use Net::SMTP
shift @ARGV; # check for recipient
if ($#ARGV < 0) # email addresses
{
print STDERR
"No recipient email provided in arguments.\n";
exit 1;
}
$smtp = Net::SMTP->new($server, Debug => $debug); # create SMTP connection
if (!$smtp) # make sure that the
{ # connection attempt
print STDERR # was successfull.
"Cannot connect to $server.\n";
exit 1;
}
if (defined($username) && defined($password)) # authenticate
{
$smtp->auth($username, $password);
}
$smtp->mail($from); # set the sender
foreach $to (@ARGV) # add each recipient
{ # to the list
$smtp->to($to);
}
$smtp->data(); # start sending the
# message body
$smtp->datasend( # some advertisement
"Received: from Mutt by mutt-smtp-wrapper.pl 1.2 "
." (www.zdo.com/articles/mutt-smtp-wrapper.shtml)\n"
);
while (<STDIN>) # send each line of
{ # message body
last if m/^\.$/g;
$smtp->datasend($_);
}
$smtp->dataend(); # terminate the
$smtp->quit; # process
_END_