Inicio > linux > How to send email from the command line – Gmail Mutt

How to send email from the command line – Gmail Mutt

Fuente:  http://go2linux.garron.me/linux/2010/10/how-send-email-command-line-gmail-mutt-789

Para errores, consultar: http://www.centos.org/modules/newbb/viewtopic.php?topic_id=40210&forum=56

And sending email while working on the command line, is good, I use it to send me notes to myself, and sometimes to send configuration files as attachments.

Is also good to have an option configured to send emails from the command line, as a way to send messages from scripts.

I will show you now how to use mutt and gmail to enable a Linux computer to send email.

Install mutt

Arch Linux

sudo pacman -S mutt

Ubuntu

sudo aptitude install mutt

Configure mutt

To configure it, we need to create ~./muttrc and put inside the file this contents

set from = "user@gmail.com"
set realname = "Guillermo Garron"
set imap_user = "user@gmail.com"
set imap_pass = "password"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = "smtp://user@smtp.gmail.com:587/"
set smtp_pass = "password"
set move = no 
set imap_keepalive = 900

Create the folders

mkdir -p /.mutt/cache

Change, for your user and your password, and you are done.

Sending emails

Now that mutt is configured it is ready to start sending emails.

mutt -s "Test from mutt" user@yahoo.com < /tmp/message.txt

And if you need to send an attachment

mutt -s "Test from mutt" user@yahoo.com < /tmp/message.txt -a /tmp/file.jpg

*-s “Test from mutt”* is the subject *-a /tmp/file.jpg* is the attachment */tmp/message.txt* is the message itself This is another way to write the test, having the body in the same line.

echo "This is the body" | mutt -s "Testing mutt" user@yahoo.com -a /tmp/XDefd.png

If you need to use send emails from a script, just use that line in the script, but be sure that is the user that has the `.muttrc` file in his / her home directory the one that runs the script.

If you liked this article please share it.

About these ads
Categorías:linux Etiquetas:
  1. Aún no hay comentarios.
  1. No trackbacks yet.

Deja un comentario

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

Seguir

Recibe cada nueva publicación en tu buzón de correo electrónico.

%d personas les gusta esto: