[ale] Need help with a Python Script

Richard Bronosky Richard at Bronosky.com
Thu Nov 17 23:19:14 EST 2011


No, Seriously. You should be using a REPL. Even if you just use the plain
python REPL, it would give you feed back as you try each line. I've updated
Steven's notes below...

> =============start script=============
>>
>> #!/usr/bin/python
>>
>> import os, smtplib
>> system_name = os.getenv('HOSTNAME')
>>
>>
>> SERVER = localhost <-- This would have given you an error. That may have
caused you to figure out the quoting thing yourself.
>>
>> FROM = "me at abc.com"
>> TO = ["you at nbc.com"]
>>
>> SUBJECT = "Mail from",os.getenv('HOSTNAME') <-- After storing this
variable, if you were to print it you'd realize that it is a Tuple, not a
string. The way to create a string is: "Mail from %s" %
os.getenv('HOSTNAME')
>>
>> TEXT = "This message is from",os.getenv('HOSTNAME') <-- Another Tuple.
>>
>> message = """\
>> From: %s
>> To: %s
>> Subject: %s
>>
>> %s
>> """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
>>
>> # Send message
>>
>> server = smtplib.STMP(SERVER) <-- If you are using ipython, typing
"smtplib." then hitting [tab] [tab] would have listed every property on the
object.
>> server.sendmail(FROM, TO, message)
>> server.quit()
>>
>> =============end script=============
>
> --
> Stephen Haywood
> Information Security Consultant
> CISSP, GPEN, OSCP
> T: @averagesecguy
> W: averagesecurityguy.info
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>



-- 
.!# RichardBronosky #!.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20111117/a7319b2b/attachment.html 


More information about the Ale mailing list