emails from command prompt.

Aruna Hewapathirane aruna.hewapathirane at gmail.com
Mon Jun 12 00:38:02 UTC 2017


<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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ca/attachments/20170611/b25b002b/attachment.html>


More information about the ubuntu-ca mailing list