emails from command prompt.

Verdi R-D verdi at azend.org
Tue Jun 13 18:08:35 UTC 2017


While quite a bit more complicated and heavy weight, you can also set up an
MTA (sendmail, postfix, exim) which sends email through Gmail as a relay
host.

Linode has a good article on it here:
https://www.linode.com/docs/email/postfix/configure-postfix-to-send-mail-using-gmail-and-google-apps-on-debian-or-ubuntu

Verdi

On Sun, Jun 11, 2017 at 8:38 PM, Aruna Hewapathirane <
aruna.hewapathirane at gmail.com> wrote:

> <snip>
>
> > 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()
>>
>
> Hello Doug,
> Have a look at the code below, 'exact same code' I sent you earlier only
> strung together as a one-liner using semi colons.
>
> ------------------------------------------------------------
> ------------------------------------------------------------
> ------------------------------------------
> import smtplib;server = smtplib.SMTP('smtp.gmail.com',
> 587);server.starttls();server.login(YOUR EMAIL ADDRESS", "YOUR PASSWORD");msg
> = "YOUR NEW MESSAGE!";server.sendmail("YOUR EMAIL ADDRESS", "THE EMAIL
> ADDRESS TO SEND TO", msg);server.quit()
> ------------------------------------------------------------
> ------------------------------------------------------------
> ------------------------------------------
>
> How easy is this to read and understand compared to what I sent earlier ?
> Both will work but the compact code is in no way faster or more efficient
> :)
>
> Try running both versions using time <program-file-name.py> and you will
> see what I mean.
>
> Readability is a very good thing. If I had to choose I would always go for
> readability first then make it correct, make it clear,
> make it concise, make it fast. In that order :)
>
> That being said if the code is only going to be ever used by no one else
> but my self then there are times I do very illegible and unreadable stuff
> but that is because I am lazy.. :)
>
> One more thing why are you emailing wan ip address around ? It is your
> code and your free to do with it as you so wish my friend but I would
> ensure no one else has access to that code if I was you :)
>
> Good work with the attachment btw !
>
> Aruna
>
>
> --
> ubuntu-ca mailing list
> ubuntu-ca at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-ca
>
>


-- 
I prefer to talk in private. Click here
<http://azend.org/resc/static/signature.asc> to get my PGP key.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ca/attachments/20170613/abf1cd83/attachment.html>


More information about the ubuntu-ca mailing list