0

I'm able to send mail using python script , here is my code

import smtplib, ssl 

smtp_server = "xxx.yyyy.com"
sender_email = "abcd@efgh.com"
receiver_email = "mnop@efgh.com"
username ='DRAETWK'
password = 'password'
message = """\
Subject: Test Mail

This message is sent from Python."""

context = ssl.create_default_context()
with smtplib.SMTP(smtp_server) as server:   
    server.login(username, password)
    server.sendmail(sender_email, receiver_email, message)
    print('Mail Sent... Check your inbox')

Mail send code is working but when I use the same user details I'm not able to read my mail I'm getting login FAILED issue , here is the code

import imaplib
import email.header
from smtplib import SMTP as SMTP


host = 'xxx.yyyy.com'
user = 'abcd@efgh.com'

login_user= 'qweqwr'
password = 'xsw2zsadsadaaq1'


# Connect to the server
print('Connecting to ' + host)
mailBox = imaplib.IMAP4_SSL(host)
mailBox.debug = 100
print(mailBox)
# Login to our account
mailBox.login(login_user, password) 

can someone help ?

pedrohreis
  • 1,030
  • 2
  • 14
  • 33
aruntheimperfect
  • 231
  • 1
  • 3
  • 11
  • Can you share the error you're getting? – Preston Badeer Jun 19 '19 at 12:41
  • File "C:\Program Files\Python\Python35\lib\imaplib.py", line 582, in login raise self.error(dat[-1]) imaplib.error: b'LOGIN failed.' – aruntheimperfect Jun 19 '19 at 13:26
  • Thank you for sharing that. Have you checked if the server firewall allows IMAP connections? Most email servers disable this by default. For example, if you're using Gmail here's a guide on how to enable IMAP https://support.google.com/mail/answer/7126229?hl=en – Preston Badeer Jun 19 '19 at 15:06
  • mine is working for gmail , now I'm trying with outlook in my office network – aruntheimperfect Jun 20 '19 at 05:59
  • Ah, good to know! Have you spoken with your office IT team to ensure your office email servers allow IMAP and allow external IP connections? – Preston Badeer Jun 20 '19 at 14:34

0 Answers0