emails from command prompt.

Aruna Hewapathirane aruna.hewapathirane at gmail.com
Sun Jun 11 20:27:34 UTC 2017


> From: Doug Stewart <doug.dastew at gmail.com>
> Date: Sun, Jun 11, 2017 at 3:29 PM
> Subject: emails from command prompt.
> To: ubuntu-ca- at lists.ubuntu.com

> I would like to make a scrip, that will be a cron job, and will send an
email to myself through gmail system.
> I am looking at sendmail but don't understand how to configure it.
> I normally use a browser to get and sent emails through gmail so I do not
have any emal servers running on my comp.
> any help would be appreciated.

Hello Doug,

The easiest way is to use Python. Put the below code in a file, say
gmail.py then run.

-------------------------------------------------------------------------------------------------------------------------
import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("YOUR EMAIL ADDRESS", "YOUR PASSWORD")

msg = "YOUR MESSAGE!"
server.sendmail("YOUR EMAIL ADDRESS", "THE EMAIL ADDRESS TO SEND TO", msg)
server.quit()
----------------------------------------------------------------------------------------------------------------------------

Substitute your actual email adress where is says "YOUR EMAIL ADDRESS" and
your actual password in "YOUR PASSWORD" and the email address you want to
send to in "THE EMAIL ADDRESS TO SEND TO"

Tested and works on my system, and you can put that in a bash script and
tell cron to run.

Hope this helps - Aruna ( Configuring postfix and smtp can be a process
that causes hair loss and baldness :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ca/attachments/20170611/398973a0/attachment.html>


More information about the ubuntu-ca mailing list