Sending mail using GNU Mailutils inside Docker container Sending mail using GNU Mailutils inside Docker container docker docker

Sending mail using GNU Mailutils inside Docker container


Install ssmtp and configure to send all mails to your relayhost.

https://wiki.debian.org/sSMTP


Thanks for the response @pilasguru. ssmtp works for sending mail from within a docker container.

Just to make the response more verbose, here are the things one would need to do.

  • Install ssmtp in the container. You could do this by the following command.

    RUN apt-get update && apt-get -y install ssmtp.

  • You could configure the configurations for ssmtp at /etc/ssmtp/ssmtp.conf

    Ideal configurations.

`

## Config file for sSMTP sendmail## The person who gets all mail for userids < 1000# Make this empty to disable rewriting.root={root-name}# The place where the mail goes. The actual machine name is required no# MX records are consulted. Commonly mailhosts are named mail.domain.commailhub={smtp-server}# Where will the mail seem to come from?rewriteDomain={domain-name}# The full hostnamehostname=c67fcdc6361d# Are users allowed to set their own From: address?# YES - Allow the user to specify their own From: address# NO - Use the system generated From: addressFromLineOverride=YES

`

  • You can directly copy that from your root directory where you're building your docker image. For eg. you keep your configurations in file named: my.conf.

    You can copy them in your docker container using the command:

    COPY ./my.conf /etc/ssmtp/ssmtp.conf

  • Send a mail using a simple command such as:

    ssmtp recipient_name@gmail.com < filename.txt

  • You can even send an attachment, specify to and from using the following command:

    echo -e "to: {to-addr}\nFrom: {from-addr}\nsubject: {subject}\n"| (cat - && uuencode /path/to/file/inside/container {attachment-name-in mail}) | ssmtp recipient_name@gmail.com

  • uuencode could be installed by the command apt-get install sharutils