Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Traceback (most recent call last):
- File "emailSend.py", line 14, in <module>
- server.login(username,password)
- File "/usr/lib/python2.5/smtplib.py", line 554, in login
- raise SMTPException("SMTP AUTH extension not supported by server.")
- smtplib.SMTPException: SMTP AUTH extension not supported by server.
- import smtplib
- fromaddr = 'user_me@gmail.com'
- toaddrs = 'user_you@gmail.com'
- msg = 'Why,Oh why!'
- username = 'user_me@gmail.com'
- password = 'pwd'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, msg)
- server.quit()
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- msg = "rn".join([
- "From: user_me@gmail.com",
- "To: user_you@gmail.com",
- "Subject: Just a message",
- "",
- "Why, oh why"
- ])
- def send_email(user, pwd, recipient, subject, body):
- import smtplib
- gmail_user = user
- gmail_pwd = pwd
- FROM = user
- TO = recipient if type(recipient) is list else [recipient]
- SUBJECT = subject
- TEXT = body
- # Prepare actual message
- message = """From: %snTo: %snSubject: %snn%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.ehlo()
- server.starttls()
- server.login(gmail_user, gmail_pwd)
- server.sendmail(FROM, TO, message)
- server.close()
- print 'successfully sent the mail'
- except:
- print "failed to send mail"
- # SMTP_SSL Example
- server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
- server_ssl.ehlo() # optional, called by login()
- server_ssl.login(gmail_user, gmail_pwd)
- # ssl server doesn't support or need tls, so don't call server_ssl.starttls()
- server_ssl.sendmail(FROM, TO, message)
- #server_ssl.quit()
- server_ssl.close()
- print 'successfully sent the mail'
- smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
- smtpserver.ehlo()
- smtpserver.starttls()
- smtpserver.ehlo()
- smtpserver.login('me@gmail.com', 'me_pass')
- (235, '2.7.0 Accepted')
- 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')
- 235 == 'Authentication successful'
- 503 == 'Error: already authenticated'
- 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')
- smtp_host = 'smtp.gmail.com'
- smtp_port = 587
- server = smtplib.SMTP()
- server.connect(smtp_host,smtp_port)
- server.ehlo()
- server.starttls()
- server.login(user,passw)
- fromaddr = raw_input('Send mail by the name of: ')
- tolist = raw_input('To: ').split()
- sub = raw_input('Subject: ')
- msg = email.MIMEMultipart.MIMEMultipart()
- msg['From'] = fromaddr
- msg['To'] = email.Utils.COMMASPACE.join(tolist)
- msg['Subject'] = sub
- msg.attach(MIMEText(raw_input('Body: ')))
- msg.attach(MIMEText('nsent via python', 'plain'))
- server.sendmail(user,tolist,msg.as_string())
- import yagmail
- yag = yagmail.SMTP('user_me@gmail.com')
- yag.send('user_you@gmail.com', 'Why,Oh why!')
- yagmail.SMTP('user_me@gmail.com').send('user_you@gmail.com', 'Why,Oh why!')
- #!/usr/bin/env python
- import smtplib
- class Gmail(object):
- def __init__(self, email, password):
- self.email = email
- self.password = password
- self.server = 'smtp.gmail.com'
- self.port = 587
- session = smtplib.SMTP(self.server, self.port)
- session.ehlo()
- session.starttls()
- session.ehlo
- session.login(self.email, self.password)
- self.session = session
- def send_message(self, subject, body):
- ''' This must be removed '''
- headers = [
- "From: " + self.email,
- "Subject: " + subject,
- "To: " + self.email,
- "MIME-Version: 1.0",
- "Content-Type: text/html"]
- headers = "rn".join(headers)
- self.session.sendmail(
- self.email,
- self.email,
- headers + "rnrn" + body)
- gm = Gmail('Your Email', 'Password')
- gm.send_message('Subject', 'Message')
- import smtplib
- server = smtplib.SMTP('smtp.gmail.com', 587)
- server.ehlo()
- server.starttls()
- server.login("fromaddress", "password")
- msg = "HI!"
- server.sendmail("fromaddress", "receiveraddress", msg)
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement