Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.image import MIMEImage
- from email.mime.text import MIMEText
- sender = "kzabuk@gmail.com"
- password_input = raw_input("Vpisi geslo:" )
- receiver = "rokzabukovec@hotmail.com"
- subject = "Python email sending"
- text = raw_input("Vpisi sporocilo, ki ga zelis poslati: ")
- msg = "From:{0}\nTo:{1}\nSubject:{2}\n\n{3}".format(sender, receiver, subject, text)
- print msg
- msg = MIMEMultipart()
- msg['From'] = sender
- msg['To'] = receiver
- msg['Subject'] = subject
- image = open("smartninja.jpg", "rb")
- msg.attach(MIMEText(text))
- msg.attach(MIMEImage(image.read()))
- image.close()
- try:
- server = smtplib.SMTP("smtp.gmail.com:587")
- server.ehlo()
- server.starttls()
- server.login(user=sender, password=password_input)
- server.sendmail(from_addr=sender, to_addrs=receiver, msg=msg.as_string())
- server.quit()
- print "Email was successfully sent to {0}!".format(receiver)
- except Exception as e:
- print "Error!"
- print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement