Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. Traceback (most recent call last):
  2. File "emailSend.py", line 14, in <module>
  3. server.login(username,password)
  4. File "/usr/lib/python2.5/smtplib.py", line 554, in login
  5. raise SMTPException("SMTP AUTH extension not supported by server.")
  6. smtplib.SMTPException: SMTP AUTH extension not supported by server.
  7.  
  8. import smtplib
  9. fromaddr = 'user_me@gmail.com'
  10. toaddrs = 'user_you@gmail.com'
  11. msg = 'Why,Oh why!'
  12. username = 'user_me@gmail.com'
  13. password = 'pwd'
  14. server = smtplib.SMTP('smtp.gmail.com:587')
  15. server.starttls()
  16. server.login(username,password)
  17. server.sendmail(fromaddr, toaddrs, msg)
  18. server.quit()
  19.  
  20. server = smtplib.SMTP('smtp.gmail.com:587')
  21. server.ehlo()
  22. server.starttls()
  23.  
  24. msg = "rn".join([
  25. "From: user_me@gmail.com",
  26. "To: user_you@gmail.com",
  27. "Subject: Just a message",
  28. "",
  29. "Why, oh why"
  30. ])
  31.  
  32. def send_email(user, pwd, recipient, subject, body):
  33. import smtplib
  34.  
  35. gmail_user = user
  36. gmail_pwd = pwd
  37. FROM = user
  38. TO = recipient if type(recipient) is list else [recipient]
  39. SUBJECT = subject
  40. TEXT = body
  41.  
  42. # Prepare actual message
  43. message = """From: %snTo: %snSubject: %snn%s
  44. """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  45. try:
  46. server = smtplib.SMTP("smtp.gmail.com", 587)
  47. server.ehlo()
  48. server.starttls()
  49. server.login(gmail_user, gmail_pwd)
  50. server.sendmail(FROM, TO, message)
  51. server.close()
  52. print 'successfully sent the mail'
  53. except:
  54. print "failed to send mail"
  55.  
  56. # SMTP_SSL Example
  57. server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
  58. server_ssl.ehlo() # optional, called by login()
  59. server_ssl.login(gmail_user, gmail_pwd)
  60. # ssl server doesn't support or need tls, so don't call server_ssl.starttls()
  61. server_ssl.sendmail(FROM, TO, message)
  62. #server_ssl.quit()
  63. server_ssl.close()
  64. print 'successfully sent the mail'
  65.  
  66. smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
  67. smtpserver.ehlo()
  68. smtpserver.starttls()
  69. smtpserver.ehlo()
  70. smtpserver.login('me@gmail.com', 'me_pass')
  71.  
  72. (235, '2.7.0 Accepted')
  73.  
  74. smtplib.SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more atn5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 g66sm2224117qgf.37 - gsmtp')
  75.  
  76. 235 == 'Authentication successful'
  77. 503 == 'Error: already authenticated'
  78.  
  79. SMTPAuthenticationError: (534, '5.7.9 Please log in with your web browser and then try again. Learn more atn5.7.9 https://support.google.com/mail/bin/answer.py?answer=78754 qo11sm4014232igb.17 - gsmtp')
  80.  
  81. smtp_host = 'smtp.gmail.com'
  82. smtp_port = 587
  83. server = smtplib.SMTP()
  84. server.connect(smtp_host,smtp_port)
  85. server.ehlo()
  86. server.starttls()
  87. server.login(user,passw)
  88. fromaddr = raw_input('Send mail by the name of: ')
  89. tolist = raw_input('To: ').split()
  90. sub = raw_input('Subject: ')
  91.  
  92. msg = email.MIMEMultipart.MIMEMultipart()
  93. msg['From'] = fromaddr
  94. msg['To'] = email.Utils.COMMASPACE.join(tolist)
  95. msg['Subject'] = sub
  96. msg.attach(MIMEText(raw_input('Body: ')))
  97. msg.attach(MIMEText('nsent via python', 'plain'))
  98. server.sendmail(user,tolist,msg.as_string())
  99.  
  100. import yagmail
  101. yag = yagmail.SMTP('user_me@gmail.com')
  102. yag.send('user_you@gmail.com', 'Why,Oh why!')
  103.  
  104. yagmail.SMTP('user_me@gmail.com').send('user_you@gmail.com', 'Why,Oh why!')
  105.  
  106. #!/usr/bin/env python
  107.  
  108.  
  109. import smtplib
  110.  
  111. class Gmail(object):
  112. def __init__(self, email, password):
  113. self.email = email
  114. self.password = password
  115. self.server = 'smtp.gmail.com'
  116. self.port = 587
  117. session = smtplib.SMTP(self.server, self.port)
  118. session.ehlo()
  119. session.starttls()
  120. session.ehlo
  121. session.login(self.email, self.password)
  122. self.session = session
  123.  
  124. def send_message(self, subject, body):
  125. ''' This must be removed '''
  126. headers = [
  127. "From: " + self.email,
  128. "Subject: " + subject,
  129. "To: " + self.email,
  130. "MIME-Version: 1.0",
  131. "Content-Type: text/html"]
  132. headers = "rn".join(headers)
  133. self.session.sendmail(
  134. self.email,
  135. self.email,
  136. headers + "rnrn" + body)
  137.  
  138.  
  139. gm = Gmail('Your Email', 'Password')
  140.  
  141. gm.send_message('Subject', 'Message')
  142.  
  143. import smtplib
  144. server = smtplib.SMTP('smtp.gmail.com', 587)
  145. server.ehlo()
  146. server.starttls()
  147. server.login("fromaddress", "password")
  148. msg = "HI!"
  149. server.sendmail("fromaddress", "receiveraddress", msg)
  150. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement