emails from command prompt.
Doug Stewart
doug.dastew at gmail.com
Sun Jun 11 21:43:29 UTC 2017
On Sun, Jun 11, 2017 at 5:18 PM, Doug Stewart <doug.dastew at gmail.com> wrote:
>
>
> On Sun, Jun 11, 2017 at 4:27 PM, Aruna Hewapathirane <
> aruna.hewapathirane at gmail.com> wrote:
>
>> > 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 :)
>>
>>
>> --
>
>
> Thanks I have this working now!!!
>
> One more question.
> I want to send a small file. I will look, but if you know how then I am
> all ears :-)
>
>
>
> <https://linuxcounter.net/user/206392.html>
>
this works but it needs to be made more compact.
--------------------------------------------------------------------------------
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("doug.dastew at gmail.com", "mypasword")
SUBJECT = "Email Data"
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
part = MIMEBase('application', "octet-stream")
part.set_payload(open("wanipadds.txt", "rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment;
filename="wanipadds.txt"')
msg.attach(part)
server.sendmail("doug.dastew at gmail.com", "doug.dastew at gmail.com",
msg.as_string())
server.quit()
-----------------------------------------------------------------------------
--
DAS[image: Certificate for 206392]
<https://linuxcounter.net/user/206392.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ca/attachments/20170611/779822ae/attachment.html>
More information about the ubuntu-ca
mailing list