Hello,
I’d like to use the mail command to send e-mails with some log files. Is there a way to configure the SMTP server from cli or to write the IP address into a file?
Thanks
Hello,
I’d like to use the mail command to send e-mails with some log files. Is there a way to configure the SMTP server from cli or to write the IP address into a file?
Thanks
You don’t need to run an additional SMTP server, you can just configure the mail command to use any existing relay. See man mailx for the settings that can be put in the configuration file.
On 2010-09-29 10:36, ionpetrache wrote:
>
> Hello,
>
> I’d like to use the mail command to send e-mails with some log files.
> Is there a way to configure the SMTP server from cli or to write the IP
> address into a file?
You can configure mailx to use an existing SMTP server (outside), or configure the local server
(postfix). This is not trivial, but YaST mail setup does it, the first part. Doing it completely is
longer, but expand your question and we’ll try to help.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
I used YaST but I was wondering if there is a way to configure mail from cli.
I looked over the manual but it doesn’t say exactly the config file. I figured that I also have to look into the postfix config files.
Thanks!
function sendmail {
if ! -f $sendmailmc.orig -a -f $sendmailmc ] ; then
echo "*** configuring postfix..."
echo " - creating /etc/postfix/sender_canonical.db ..."
admin=${admin2add%% *}
printf "root
%s
%s
%s
" $user2add | awk 'BEGIN { EMAIL = "@'"$host1.$mydomain"'" ; printf "root '"$admin@$enveloppe"'
" } ; { if ($1 == "root") print $1 EMAIL, " '"$admin@$enveloppe"'" ; else print $1 EMAIL, " " $1"@'"$enveloppe"'"}' > /etc/postfix/sender_canonical
/usr/sbin/postmap /etc/postfix/sender_canonical
echo " - creating /etc/postfix/transport.db ..."
cat > /etc/postfix/transport << EOFTRANSPORT
$host1.$mydomain local:
localhost.$mydomain local:
$mydomain :
.$mydomain :
* smtp:${smarthost}]
EOFTRANSPORT
/usr/sbin/postmap /etc/postfix/transport
cp $sendmailmc{,.orig}
echo "*** updating $sendmailmc..."
cat << EOFSENDMAILMC | sed -f - ${sendmailmc}.orig > $sendmailmc
s|mydestination = \$myhostname, localhost.\$mydomain.*|&, localhost|
s|^mynetworks_style = subnet.*|mynetworks = ${DIP[0]}.0/24, 127.0.0.0/8|
/^relayhost =/a \
transport_maps = hash:/etc/postfix/transport
EOFSENDMAILMC
#patching /etc/sysconfig/mail
grep -q 'SMTPD_LISTEN_REMOTE="yes"' /etc/sysconfig/mail || {
cp /etc/sysconfig/mail{,.orig}
sed 's|^SMTPD_LISTEN_REMOTE=.*|SMTPD_LSITEN_REMOTE="yes"|' /etc/sysconfig/mail.orig > /etc/sysconfig/mail && rm /etc/sysconfig/mail.orig
}
-f /etc/mail/aliases.db ] || newaliases
# restarting postfix
/etc/rc.d/postfix start || /etc/rc.d/postfix reload
fi
echo "sendmail successfully configured" | mail root
}
That’s how I do it. Of course, you don’t have any of the variables in my example, but it might give you an idea.
On 2010-10-01 14:36, ionpetrache wrote:
> I used YaST but I was wondering if there is a way to configure mail
> from cli.
Yes, if you are experienced in postfix configuration.
As you are not - or you would not be asking - use Yast. I insist. If you don’t like X mode, do it in
text mode. If it is a remote or headless server, use ssh.
> I looked over the manual but it doesn’t say exactly the config file.
Which manual? Postfix? It has several. Mailx? Read “man mailx”.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
If it isn’t clear, a common procedure (usually on a Server, not a client machine but is essentially the same),
Most times when you install Postfix or Sendmail the default configuration is to permit relaying through only the machine itself (typically “localhost”), YMMV.
If you do this, you’re already set to go without any custom config. It’s then noob simple to then use any environment from within any application and even from the command line to send mail by pointing to the localhost, you should find numerous examples of this on the Internet. Sending from a command line is also a common way for SysAdmins to troubleshoot and for hackers to probe and sometimes illegally send mail through unauthorized SMTP relays.
So, to get you going…
After installing your SMTP Server of choice
You can test whether it’s running and the network port is open
telnet localhost 25
It should return your SMTP server’s banner.
If successful, you should then be able to follow your guide of choice from the Internet on creating a message from the command line, note that it’s likely you will not have to pass any User/Password authenticaion. If credentials are required(unlikely), then a User on the local machine should suffice.
HTH,
Tony