Next: , Previous: , Up: sendmail script   [Contents][Index]


A.6.3 Reading host informations from file

For each SMTP server we need the following informations: the hostname, the port number, the session type, the authorisation method. There are two ways to specify these:

If --host is not used: the hostname defaults to localhost. If the selection of port, session type or authorisation type is left unspecified: The script automatically looks into the default hostinfo file. Informations from command line options supersede informations from the hostinfo file.

The default pathname for the hostinfo file is $HOME/.mbfl-hostinfo and can be overridden by the --host-info option. The format of this file is line oriented: Blank lines are ignored, lines starting with a # character are comments, lines starting with machine are host records.

Each record line must have the format:

machine <host> service <name> port <number> session <type> auth <type>

for example:

# ~/.mbfl-hostinfo --
#

# SMTP servers
machine localhost service smtp port 25 session plain auth none
machine relay.poste.it service smtp port 465 session tls auth login
machine smtp.gmail.com service smtp port 587 session starttls auth plain

# POP3 servers
machine pop.tiscali.it service pop3 port 110 session plain auth userpass
machine relay.poste.it service pop3 port 995 session tls auth userpass
machine pop.googlemail.com service pop3 port 995  session tls auth userpass

### end of file

so that we can extract a record with the following script:

file=~/.mbfl-hostinfo
host=gmail
service=smtp

rex='^[ \t]*'
rex+='machine[ \t]\+.*%s.*[ \t]\+'
rex+='service[ \t]\+%s[ \t]\+'
rex+='port[ \t]\+[0-9]\+[ \t]\+'
rex+='session[ \t]\+\(plain\|tls\|starttls\)[ \t]\+'
rex+='auth[ \t]\+\(none\|plain\|login\)'
rex+='[ \t]*$'
rex=$(printf "$rex" $host $service)

set -- $(grep "$rex" "$file")
echo machine $2
echo service $4
echo port    $6
echo session $8
shift 9
echo auth    $1

currently sendmail-mbfl.sh parses the file using the =~ regular expressions operator.

Notice that when using the hostinfo file, the value of the --host option can be a substring of the host name.


Next: , Previous: , Up: sendmail script   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.