0

I'm on a work network. I want to be able to download the attachment from coming from a specific email address to my local directory. But, for that first I need to be able to connect to the mail server. I'm doing the following to connect:

self.connection = imaplib.IMAP4_SSL(mail_server)
self.connection.login(username, password)
self.connection.select(readonly=False)

However the above gives me "Connection Refused error". However, when I do this:

mail_server=smtplib.SMTP('smtp.something.com')
print(mail_server)

It makes the connection. Is there a way I could use SMTP instead of imaplib.IMAP4_SSL(mail_server) to be able to download attachments from email? Or some other work around?

akrama81
  • 341
  • 1
  • 7
  • 18
  • You should specify a port number alongside the mail_server (993 i guess), try that way, should be enough, otherwise it might be a proxy/firewall problem `self.connection = imaplib.IMAP4_SSL(mail_server, 993)` – MrRobot Aug 01 '17 at 21:58
  • @MrRobot No, 993 does not work. I mentioned that I'm on a work network, so yes there is firewall, but smtp works, so I wanted to know if there was a workaround to this (imaplib) as well. – akrama81 Aug 01 '17 at 22:29
  • Did you try poplib ? I honestly don't know of a way to workaround this with smtp... – MrRobot Aug 01 '17 at 22:41
  • 1
    SMTP can only send mail, not receive it. – Max Aug 03 '17 at 00:14

0 Answers0