hamilc
Posts: 178
Joined: Fri May 16, 2014 9:59 pm

What can I import?

Fri Jun 13, 2014 9:24 pm

I was just reading a topic on this forum about sending an email. I had no idea this could be easily done. I noticed that the command "import email" was used along with a few others I did not recognize. Where are all of the available things to import listed? Once I "import email" how do I find out how to use the library, where is email documented? Thanks.

ThomasS
Posts: 118
Joined: Thu Jan 23, 2014 7:05 pm
Location: Leeds
Contact: Website

Re: What can I import?

Fri Jun 13, 2014 9:32 pm

I assume you mean in python. If so, email is documented at https://docs.python.org/2/library/email.html . Libraries such as this one allow you to use countless more features in python. Some, like email, come pre-installed with python, but others, such as twython, need to be downloaded. For this reason, I am not aware that there is a complete list of python libraries. Hope this helps!
ThomasS

User avatar
DougieLawson
Posts: 38536
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: What can I import?

Sat Jun 14, 2014 10:07 am

Try this python3 program

Code: Select all

#!/usr/bin/python3
import time
from datetime import datetime
import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

f_time = datetime.now().strftime('%a %d %b @ %H:%M')

domain = 'xxx-xxx-xxx-xxx.myinternetisp.co.uk' # redacted
toaddr = '[email protected]'    # redacted
me = '[email protected]' + domain
subject = 'Test email @ ' + f_time

msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "Tester @ " + f_time

textforbody = "This is a test email from my Raspberry Pi"

stuff = MIMEText(textforbody, 'plain')
msg.attach(stuff)

try:
   s = smtplib.SMTP('localhost')
   s.send_message(msg)
   s.quit()
except:
   print ("Error: unable to send email")
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

hamilc
Posts: 178
Joined: Fri May 16, 2014 9:59 pm

Re: What can I import?

Sat Jun 14, 2014 12:10 pm

I will try this. I have learned a lot over the past twodays. Thanks

Return to “Python”