How to Read Emails using IMAP Download Attachments Python 3 for Beginners 2018

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024

ความคิดเห็น • 239

  • @cspidermx
    @cspidermx 6 ปีที่แล้ว +10

    Thanks a lot man! I've been getting crossed eyed trying to read the documentation for this and you are the first resource I've find that makes it into something understandable.

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว +4

      Thanks! when I first started looking into IMAP I had the same problem and that is exactly why I made this video, to make it easier to understand.
      Many thanks
      Samuel

  • @hamzadlm6625
    @hamzadlm6625 6 ปีที่แล้ว +20

    next time zoom in the text ctrl + so we can see it clearly, thanks for the vid

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว +1

      Thanks, I will take this into account in future

  • @katherinepotter7738
    @katherinepotter7738 5 ปีที่แล้ว +5

    This is amazing! I have one question: how would you alter the code to retrieve the most recent email with a specific subject? Or does the email always have to be in a specific position in the inbox?

  • @stevemooers5180
    @stevemooers5180 5 ปีที่แล้ว +1

    Thank You Sir! You just saved me hours and hours of frustration trying to implement this.... Excellent job !!!

  • @slimanemzerguat3298
    @slimanemzerguat3298 6 ปีที่แล้ว +7

    thanks bro but can i suggest something plzzzz use a bigger font or reduce your screen resolution it's so hard to read your code in that super screen you have there

  • @noo0b28
    @noo0b28 4 ปีที่แล้ว +3

    Hi, nice video
    I have a question, is anyway to strip the content of the email so i dont get b/ n/ r/ like in 9:43?

  • @onionpsi264
    @onionpsi264 5 ปีที่แล้ว +3

    I'm pretty sure *continue* means that you skip the rest of the current iteration of a loop. I was kinda confused by your explanation as to why def get_attachments() is structured the way it is. If i had to guess it is because if a "part" doesn't meet any of several criteria (is multipart, doesn't have a filename etc.) we actually *don't* want to try to extract the attachment from it because it could throw an error.
    I actually had to remove the "Content-Disposition" restriction from the loop to identify attachments, not sure why though.

    • @pointer333
      @pointer333 2 ปีที่แล้ว

      Yes, continue means the opposite of what was stated in this video. It STOPS the loop where it is, and returns to the beginning of the loop, so it can iterate again, but on the NEXT part. So this code is really saying that if the message IS multipart, ignore it and check the next one. And if the content disposition is None, then ignore the message and check the next one. Now I'm hella confused. Do we always know that a multipart email will NOT contain an attachment? Will emails with no content disposition always NOT have attachments?

  • @azr_sd
    @azr_sd 3 ปีที่แล้ว +1

    excellent video mate.Please make more videos like this.. Thanks again

  • @harshmudgil4140
    @harshmudgil4140 4 ปีที่แล้ว +1

    A video worth a million likes. Thanks.

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว +1

      Thank you!

  • @Danielchall25
    @Danielchall25 4 ปีที่แล้ว +2

    I'm a few years late but brilliant video.

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว +1

      Thank you!

  • @klausdoerr9069
    @klausdoerr9069 5 ปีที่แล้ว +1

    Yes, helpful, could read mails and save attachments. Thank you very much for the great support.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      You're most welcome!

  • @HotPlasticHull
    @HotPlasticHull 6 ปีที่แล้ว +3

    thank you so much, your method to extract the body made my day :*

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว +1

      Thanks HotPlasticHull,
      Glad this video helped!

  • @asdasd-bs7nw
    @asdasd-bs7nw 5 ปีที่แล้ว +3

    thanks a lot bro. it is really easy way for python beginners. Your code and explanation were so easy to understand for me

  • @gideonifeanyimmeremnwanne9969
    @gideonifeanyimmeremnwanne9969 5 ปีที่แล้ว +2

    Hello Sammy, this was really a great video... it shows how greatly you understood the concept... Thanks man, You are the man. . . you just made my project a bit closer to closure... thanks man

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Thank you!

  • @pavlo01
    @pavlo01 4 ปีที่แล้ว +3

    Just what I needed, thank you for your help!

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Awesome! You're welcome - glad to help.

  • @radugoguta5634
    @radugoguta5634 5 ปีที่แล้ว +1

    Thanks you very much for the video - really helpful :) I have 1 question - how to read both the attachment and the body of the email, I don't understand where the body disappears .

  • @MarcelMilcent
    @MarcelMilcent 4 ปีที่แล้ว +2

    Thank you very much!! A question on a problem you may not have: I am having trouble decoding the body text, which, in my case, comes in a weird get around of latin characters. (like "operação" reads "opera\xc3\xa7\xc3\xa3o") I have seen some examples for handling it with the standard Python Lib quopri, but I could not make it work. Any thoughts?

    • @MarcelMilcent
      @MarcelMilcent 4 ปีที่แล้ว +1

      Just found out. Simply get the bytes message and msg.decode('utf-8'). Simpler than I expected.

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Excellent to see you solved it.

  • @ravindumirihana2784
    @ravindumirihana2784 6 ปีที่แล้ว +2

    This tutorial is so good. It actually worked! Thanks.. (Suggestion :- code is little bit hard to see with small font) Thankyou for the great video!

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +Ravindu Mirihana Hi there, many thanks I try hard to make videos to help others.
      If you are struggling to read the code there is a link to the full code in the video.
      I would recommend watching on a computer in order to get the most out of the video.
      Many thanks
      Samuel

  • @dcemaildc7921
    @dcemaildc7921 4 ปีที่แล้ว +1

    I get an error when trying to run the code
    Traceback (most recent call last):
    File "D:\\python\imapreadEmail.py", line 8, in
    con.login(user,password)
    File "C:\Python3\lib\imaplib.py", line 598, in login
    raise self.error(dat[-1])
    imaplib.IMAP4.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
    Tried the below but still the issue 'allow less secure apps to access your account" . Please some tips

  • @baladakshinamoorthi2988
    @baladakshinamoorthi2988 5 ปีที่แล้ว +1

    Other than "email" mentioned in import impalib,email - no where email is mentioned in the code - so last line raw = email.message_from_bytes(data[0][1]) how email is throwing an error AttributeError: module 'email' has no attribute 'message_from_bytes'

  • @jamesadinata1372
    @jamesadinata1372 5 ปีที่แล้ว +3

    Great work man! Thanks a lot, this is really helpful!

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Thank you, glad it's helpful.

  • @thomasyang1
    @thomasyang1 3 ปีที่แล้ว

    I know it's been 3 years, but just want to let you know that it's still useful in 2021!

    • @HowToFAQ
      @HowToFAQ  3 ปีที่แล้ว

      Thank you Thomas!
      Glad to help, let us know what you are working?

    • @udayreddy7255
      @udayreddy7255 2 ปีที่แล้ว

      @@HowToFAQ hello sir i cannot download pdf attachment . the program is running fine but the pdf is not being downloaded please help

  • @MegaGrac777
    @MegaGrac777 2 ปีที่แล้ว

    Very helpful!
    Thx you

  • @ZeroDebtInvestments
    @ZeroDebtInvestments 4 ปีที่แล้ว

    How do I get the Python 3.6.0 Shell on the right side? Is that just command prompt? At 2:29 you say let's do F5 and you get ===RESTART: C: "location where the file is saved". It doesn't work for me.

  • @canyousmellthejazz3909
    @canyousmellthejazz3909 4 ปีที่แล้ว +2

    raw = email.message_from_bytes(data[0][1])
    TypeError: 'NoneType' object is not subscriptable

  • @nimmitripathy940
    @nimmitripathy940 2 ปีที่แล้ว

    Hello !! Nice Video, I loved it, it took days for me to find this vid
    The code which you showed extracts data from emails backwards. I mean to say that it counts the oldest email first. Is there any way I can fetch data from the latest email??
    Pls reply

    • @HowToFAQ
      @HowToFAQ  2 ปีที่แล้ว +1

      Hi,
      If you are talking about how to get the emails from search in reverse order just change line from:
      for num in result_bytes[0].split()
      To:
      for num in result_bytes[0].split()[::-1]
      Hope this helps
      Many thanks
      Samuel

  • @shahinashaik4284
    @shahinashaik4284 5 ปีที่แล้ว +1

    Thanks Man.... Really you helped me alot.......

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      You're welcome!

  • @danieleldridge7560
    @danieleldridge7560 4 ปีที่แล้ว

    @HowToFAQ Do you know how to do the same with outlook? I have been looking everywhere but no one seems to have the code anywhere??

  • @sahilbhat4493
    @sahilbhat4493 2 ปีที่แล้ว

    how to do it for a list suppose i have 100 email accounts file and i wanna get the list of the email messages i recieve in each of them in my computer without logging each manually-please reply

  • @karishmagangwani1951
    @karishmagangwani1951 3 ปีที่แล้ว

    Is there a way to customize this to download attachments from unread emails instead of indexing it b'9' or something?

  • @MalikTheGeek07
    @MalikTheGeek07 11 วันที่ผ่านมา

    If you're looking at this in 2024, the new way of downloading attachments is:
    for att in msg.attachments:
    filepath = os.path.join(ATTACHMENT_DIRECTORY, att.filename)
    with open(filepath, "wb") as f:
    f.write(att.payload)
    f.close()

  • @abhisvlogs2863
    @abhisvlogs2863 5 ปีที่แล้ว +1

    Hi , if I have to get names, email address, contact number, and the year/month of everyone who has contacted me on Gmail so far, what should I do?

  • @Trending-video-latest
    @Trending-video-latest 2 ปีที่แล้ว

    we need any format email invoice file save in mysql databse in python programming laguage

  • @snehankitchikhalekar5186
    @snehankitchikhalekar5186 4 ปีที่แล้ว

    hello sir how to check how many mails having attachments or is there any method to process only those mails which are having attachments

  • @nagrajvirnodkar6297
    @nagrajvirnodkar6297 4 ปีที่แล้ว

    Thanks a lot Sir
    really encouraging

  • @JohnHour
    @JohnHour 5 ปีที่แล้ว +1

    Hi, may I know how to detect the latest email based on your code? Can you provide an example? Thank you.

    • @MACHINEBUILDER
      @MACHINEBUILDER 5 ปีที่แล้ว +2

      when you first select the email,
      use this code :...
      Replace the line :
      _result, data = con.fetch(b'10', '(RFC822)')_
      With the following code :
      (retcode, messages) = con.search(None, 'ALL')
      if not retcode=='OK':
      print("UNHANDLED ERROR : RETCODE NOT OK :")
      print(retcode)
      input('...')
      recent_id = messages[0].split()[-1:][0]
      result, data = con.fetch( recent_id, '(RFC822)' )
      Hope that works!!! :)

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว +1

      Hi there,
      This will work in principle, but there is a fundamental problem with code since it gets all the email in the inbox, which may take a very long time for an inbox with a lot of emails. I suggest you get the size of the inbox (number of messages) then select the message using that number. There a few examples on stackoverflow that may be useful stackoverflow.com/questions/31218582/how-to-fetch-last-10-messages-from-imap-server
      Hope this helps!
      Many thanks
      Samuel

    • @MACHINEBUILDER
      @MACHINEBUILDER 5 ปีที่แล้ว

      @@HowToFAQ yeah that does seem like it would be faster... :)

    • @JohnHour
      @JohnHour 5 ปีที่แล้ว

      @@HowToFAQ Thank you for suggestion. If for email with attachment, how to get the attachment's filename? Thank you.

  • @henrydupuis5081
    @henrydupuis5081 6 ปีที่แล้ว

    Thank you for your great work,
    when I read an email with your pyton script, the mail is not really open, it is still in bold text in my mail box. Do you know how can I handle that, such that gmail detectes all my emails have been opened? (I don't want to use mark as read)

    • @henrydupuis5081
      @henrydupuis5081 6 ปีที่แล้ว

      Like if I really clicked on the mail

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there, I am not actually sure what you mean, are you suggesting you want to read emails and then mark them in some way as read other than the usual way. (Possibly by assigning a label to an email)

    • @henrydupuis5081
      @henrydupuis5081 6 ปีที่แล้ว

      Not really, I was thinking to this kind of code:
      there is n mail in my mailbox
      i = 1
      while i < n:
      mail(i).open()
      mail(i).close()
      i += 1
      So it does not read the mails but opens them
      Do you think it is possible to code this kind of thing?
      I did not find anything on the net.

  • @shuvankarbiswas9627
    @shuvankarbiswas9627 4 ปีที่แล้ว +1

    Getting this error:
    AttributeError("module 'imaplib' has no attribute 'imap4_ssl'"
    Please help

  • @TheGreenCheeseMoon
    @TheGreenCheeseMoon 6 ปีที่แล้ว

    Helpful vid, thanks!

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      You're welcome, glad you found useful!

  • @pdfconvert9702
    @pdfconvert9702 6 ปีที่แล้ว

    Thanks!! helped me a lot... please upload more videos!

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Thanks! I will be doing so soon!

  • @mohamedamineboulaayoun6625
    @mohamedamineboulaayoun6625 5 ปีที่แล้ว +3

    Hi man i get this error AttributeError: module 'email' has no attribute 'message_from_bytes' im using python 3.7.2

    • @AndreiSota
      @AndreiSota 5 ปีที่แล้ว

      Same here!

    • @jockillfull
      @jockillfull 4 ปีที่แล้ว

      It's late but are you running a python3 shell ?
      This usually occurs on python2

    • @swagteck8925
      @swagteck8925 4 ปีที่แล้ว +2

      by me, it was a file that I named email. so just rename.

    • @DylanWeicker
      @DylanWeicker 4 ปีที่แล้ว

      @@swagteck8925 Thanks a lot! I had this problem but it was because I was working in a file called email.py

  • @nisarahamad1455
    @nisarahamad1455 5 ปีที่แล้ว

    Hi Samuel,
    This is very helpful and nice explanation. I have one problem statement please upload video on this
    Scenario : In my inbox i have lots of email in that some emails contains CV or Resume of a person as an attachments i need to downolad those attachment (word/pdf) using code
    It will be more helpful
    Thanks in advance

  • @correo-se1ro
    @correo-se1ro 5 ปีที่แล้ว

    Hello. Pyhton doesnt return anythingn once I run until con.select . It is not an error, nor an output. its just blank. How could I fix that? thanks!

  • @KNT_19
    @KNT_19 4 ปีที่แล้ว

    Nice tutorial

  • @PraveenKumar-pd9sx
    @PraveenKumar-pd9sx 4 ปีที่แล้ว +1

    Can I extract the body of all emails?

  • @saivipulchakravarthy8853
    @saivipulchakravarthy8853 4 ปีที่แล้ว

    Great tutorial!!
    Thanks in advance, I got an error as below:
    error:
    imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
    I have enabled the IMAP service in Gmail settings and enabled the less security apps option in google account. Even though I'm getting the same error. Can anyone help me out?

  • @bouchervilleoffice8896
    @bouchervilleoffice8896 6 ปีที่แล้ว +1

    I am get an error
    Traceback (most recent call last):
    File "/home/pi/display.py", line 61, in
    get_attachments(raw)
    File "/home/pi/display.py", line 33, in get_attachments
    for part in msg.walk(''):
    AttributeError: 'str' object has no attribute 'walk'
    Please help

  • @baladakshinamoorthi2988
    @baladakshinamoorthi2988 5 ปีที่แล้ว +1

    I am getting an error - raw = email.message_from_bytes(data[0][1])
    result, data = con.fetch(b'1','(RFC822)')
    AttributeError: module 'email' has no attribute 'message_from_bytes' , eventhough i have first two emails[ from top in my Inbox] [recent] , any suggestion is much appreciated.

    • @baladakshinamoorthi2988
      @baladakshinamoorthi2988 5 ปีที่แล้ว

      top two [recent emails] has pdf attachments

    • @baladakshinamoorthi2988
      @baladakshinamoorthi2988 5 ปีที่แล้ว

      Other than "email" mentioned in import impalib,email - no where email is mentioned in the code - so last line raw = email.message_from_bytes(data[0][1]) how email is throwing an error AttributeError: module 'email' has no attribute 'message_from_bytes'

  • @lynnwillis4332
    @lynnwillis4332 3 ปีที่แล้ว

    Def Search does not work. I am using Anaconda. It's loaded as such:
    def search(key,value,con):
    result, data = con.search(None,key,'"{}"'.format[value])
    return data

  • @shrutisharma1904
    @shrutisharma1904 3 ปีที่แล้ว

    Can IMAP return a certain text/number (mobile no if there is any in email body) ? if yes how ?

    • @HowToFAQ
      @HowToFAQ  3 ปีที่แล้ว

      IMAP as a protocol, to my knowledge, does not automatically extract mobile phone numbers, however, you could easily use the module python regex module re to match mobile numbers in the body's text.
      Many thanks
      Samuel

  • @faizanshaikh9380
    @faizanshaikh9380 3 ปีที่แล้ว

    Hello,
    It's showing me an IMAP error at imap_server.select("inbox") after login as "user is authenticated but not connected", so what can we do in this case ?

  • @avivbarel2694
    @avivbarel2694 4 ปีที่แล้ว

    hey , hope it is still relavent , when trying to save the file it doesn't save it although I give it the an exisiting path

  • @Joe_Gold
    @Joe_Gold 4 ปีที่แล้ว

    What screens am i seeing? I use PyCharm and new to python.

  • @elrividlagente
    @elrividlagente 5 ปีที่แล้ว

    I have the following error:
    Traceback (most recent call last):
    File "LeeCorreos6.py", line 48, in
    raw = email.message_from_bytes(data[0][1])
    TypeError: 'NoneType' object is not subscriptable
    could you tell me how to fix it, the code did not work.. Thanks!!

  • @samharris9880
    @samharris9880 6 ปีที่แล้ว +1

    Hi, This has been really helpful. But how could you collect the latest email. I've attempted to do it through the length of the inbox but it doesn't like the variable. Bit Stuck, Any Idea?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      The variable you pass for email id has to be in byte form. E.g b'1023'

    • @samharris9880
      @samharris9880 6 ปีที่แล้ว +1

      yes, i get that. And it worked as such. But i'm trying to get the latest email. So as a variable.
      it looks like this?
      InboxLen = str(con.select('INBOX'))
      #print(InboxLen)
      removechars = "'(),[]OKb"
      for char in removechars:
      InboxLen = InboxLen.replace(char,'')
      #print(InboxLen)
      InboxLen = PAD(InboxLen)
      InboxLen_bytes = InboxLen.encode('utf-8')
      #This is where the number on enmail
      result, data = con.fetch(b''+InboxLen_bytes+'','(RFC822)')

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there, get the size of the inbox as an integer for example.
      Then doing the following
      bytes_id = bytes(str(inbox_len),'UTF-8')

    • @samharris9880
      @samharris9880 6 ปีที่แล้ว

      so turn Inbox_Len to an integer then call that line? Thanks for the reply too.

    • @samharris9880
      @samharris9880 6 ปีที่แล้ว

      It now looks like this?
      InboxLen = str(con.select('INBOX'))
      #print(InboxLen)
      removechars = "'(),[]OKb"
      for char in removechars:
      InboxLen = InboxLen.replace(char,'')
      #print(InboxLen)
      InboxLen = int(InboxLen)
      bytes_id = bytes(str(InboxLen),'UTF-8')
      #This is where the number on enmail
      result, data = con.fetch(b''+InboxLen+'','(RFC822)')
      #result, data = con.select("INBOX")
      TxtBody = email.message_from_bytes(data[0][1])
      print(CollectEmailBody(TxtBody))#prints the emails text
      app.setMessage("EmailBody",str(TxtBody))

  • @judeleon8485
    @judeleon8485 4 ปีที่แล้ว +1

    This is supposed to a great tutorial but the text is just too small to be seen which make the tutorial almost meaningless. It seems you did not view it before posting it, or is there something I'm not doing right on my side?

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว +1

      Hi Jude,
      My apologies for the text being too small in future videos, I am looking to make the code more readable.
      As with many of my videos you can find the source code in the link in the description this should make it easier since you copy and paste section of code.
      I would recommend watching in a laptop or desktop with the quality set to 1080p in order to ensure maximum readability.
      Hope this helps!
      Many thanks
      Samuel

  • @sunilkumargupta7980
    @sunilkumargupta7980 5 ปีที่แล้ว

    Very nice video... Sir,
    I just want to know how to work with outlook mails?

  • @artofmeditation2023
    @artofmeditation2023 4 ปีที่แล้ว

    Actually the attachment is not able to being downloaded.Ca you please tell me for solution??

  • @shashyb
    @shashyb 5 ปีที่แล้ว

    Hi, Nice video. I was able to work through everything except for getting the attachment. I am running python on mac and I am getting the following error:
    filePath = os.path.join(attachment_dir,fileName)
    NameError: name 'os' is not defined
    Please let me know how to fix it.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Just add "import os" at the top line of your code

    • @shashyb
      @shashyb 5 ปีที่แล้ว

      @@HowToFAQ Hey, that worked. Thanks a lot!
      Your videos are pretty thorough and I am able to do a cool project with this.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Thanks, you're welcome! Glad you found it helpful. Any programmatic challenges you still need help with ?

  • @delabere
    @delabere 6 ปีที่แล้ว +1

    Nice one mate - this is really helpful. Is there a way to search for only unread email messages?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว +1

      +Jack Rickards Hi there, yes there is an easy way to search for unread messsges.
      status, response = con.search(None, 'INBOX', '(UNSEEN)')
      Hope this helps!
      Many thanks
      Samuel

    • @delabere
      @delabere 6 ปีที่แล้ว

      I am getting this error: error: SEARCH command error: BAD [b'Could not parse command']
      Any idea why?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +Jack Rickards Hi there,
      I realised I included 'INBOX' but the program has at this point already selected the inbox.
      It should be
      result, data = con.search(None, '(UNSEEN)')
      This should fix it.

  • @sowmyamg7271
    @sowmyamg7271 4 ปีที่แล้ว

    I want to download all the attachments in single run so how should i do?

  • @shravankumarchintham2496
    @shravankumarchintham2496 5 ปีที่แล้ว

    hii, it worked well for me. Thank you so much. And I got a requirement on this.
    Could you please explain how to fetch the basic profile details of a user from a particular mail id instead of getting inbox, personal and sent item mails??
    please help me in this. Thanks in advance.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Hi there,
      Would you be able to clarify what you mean?
      Do you mean you want to be able to find the user information from the email id like display name etc.
      In which you will need to use the email provider API for example GMAIL API. I've made videos on the Gmail API you will need to look at Gmail API documentation to see how to the users profile information.
      Or do you mean something else ?
      Many thanks
      Samuel

    • @shravankumarchintham2496
      @shravankumarchintham2496 5 ปีที่แล้ว

      @@HowToFAQ Yes, exactly the same thing I need i.e., user's basic profile information like his/her name, gender, mobile number and date of birth etc. from the mail id.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Hi there,
      You could use the following function from the Gmail API: developers.google.com/gmail/api/v1/reference/users/getProfile

    • @shravankumarchintham2496
      @shravankumarchintham2496 5 ปีที่แล้ว

      @@HowToFAQ hi, could you explain how can we try this pro-grammatically using python?

  • @joeyshias
    @joeyshias 5 ปีที่แล้ว +1

    Thank you very very much

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      You're welcome, glad you liked the video.

  • @karanpatel6111
    @karanpatel6111 3 ปีที่แล้ว

    Hi Sir, Not able to download PDF from email.

  • @guillermoyanezfeliu8269
    @guillermoyanezfeliu8269 5 ปีที่แล้ว

    Hey man thanks a lot!!
    I just have a problem: I'm pretty sure there are emails with .txt attached files. Anyways the code works, when I print "data" it shows the whole message, but not puts any attachment.
    The other thing is when it finally finds an attached file - which is an image - it throws an error:
    FileNotFoundError: [Errno 2] No such file or directory: 'C:/Usuarios/Guillermo Yañez/Desktop/Correos/image001.jpg'
    It seems yeah, it is trying to open a file that doesn't exists to actually create it.
    Any help?
    Thanks in advance.

    • @guillermoyanezfeliu8269
      @guillermoyanezfeliu8269 5 ปีที่แล้ว

      I just needed to change this:
      if part.get('Content-Disposition') is 'NoneType': instead of 'None'

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Cool, glad you got it fixed !

  • @ohtych1004
    @ohtych1004 4 ปีที่แล้ว

    4:46 I couldn’t read that, what did it say? Thanks!

  • @jjtamilchennal7398
    @jjtamilchennal7398 6 ปีที่แล้ว +1

    hi I want to download all the attachments from different mails ,con.fetch(b'2','(RFC822)') its download the attachements from one mail how to change this one

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there,
      I made a script that iterates through a whole inbox of emails and downloads all the attachments. If you want to download all the attachments from multiple emails I would recommend running this script on multiple emails etc..
      Currently it downloads attachments appending the email id to the attachment file name and then save the file in the attachment dir defined in the script.
      Here is a the link: ghostbin.com/paste/m3jk6
      Many thanks
      Samuel

    • @wavesailor
      @wavesailor 6 ปีที่แล้ว

      Sam thanks for tutorial. And your ghostbin code works great except I ran into a few problems:
      Firstly: Found a bug - this line should read like this:
      result, data = con.fetch(str(email_id).encode(),'(RFC822)')
      Secondly: some of the filenames caused a few problems as they had : or \ / in the name.
      I used code I found here to sort this problem out:
      stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename/#698714
      BUT my main issue is that I get this error now an I don't know how to solve it;
      "in get_attachments
      fileName = '{} '.format(email_id)+part.get_filename()
      TypeError: must be str, not NoneType"
      Any Ideas?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there, I would need to see the full code

    • @wavesailor
      @wavesailor 6 ปีที่แล้ว

      Seems this is the cause of the problem - It does not have a filename:
      ------=_Part_12583811_1673937343.1444906500669
      Content-Type: text/html
      Content-Transfer-Encoding: quoted-printable
      Content-ID:
      Content-Disposition: inline
      New Page 1
      =20
      [snipped]
      Not sure how to handle this exception?

    • @corybunge5209
      @corybunge5209 4 ปีที่แล้ว

      HowToFAQ the ghost bin link unfortunately does not work anymore - is this script still
      Available?

  • @gaurakshakautilya3447
    @gaurakshakautilya3447 5 ปีที่แล้ว

    Hi , i am having problem with login throwing error like log in failed please suggest i m using office 365

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Enable access via smtp and use the correct smtp address

  • @Pablo-wy1ui
    @Pablo-wy1ui 4 ปีที่แล้ว +1

    One moment , let me go for my telescope :v

  • @dimatarasiuk8027
    @dimatarasiuk8027 5 ปีที่แล้ว

    Hi, I got an error: "imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)"
    on con.login(login,password) line.
    But I use correct credentials, I checked twice. Could smb explain what is wrong?

    • @dimatarasiuk8027
      @dimatarasiuk8027 5 ปีที่แล้ว

      I found. Problem is in account settings.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Yes, most likely insecure apps wasn't enabled?

  • @bunkoti
    @bunkoti 4 ปีที่แล้ว

    Can't see anything, which is a shame, given the valuable information that you are providing

  • @MuralyTechnos
    @MuralyTechnos 4 ปีที่แล้ว

    Authentication issue I am facing . why?

  • @srkstudy1302
    @srkstudy1302 5 ปีที่แล้ว

    thank you ..

  • @bhaskarsrivastava5654
    @bhaskarsrivastava5654 6 ปีที่แล้ว

    Hello,
    Video is really useful, but when I am trying to run the script in my anaconda for Python, I am getting (ok,b'1) and like wise. Which is giving me error when I am trying to fetch the attachment. I know the problem is because ok 'ok' which I am getting, as I can fetch the proper attachment when I hardcode the binary value.
    Any suggestions??

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there,
      You need to correctly extract the binary value from the "ok" response the it should work.
      Many thanks
      Samuel

    • @bhaskarsrivastava5654
      @bhaskarsrivastava5654 6 ปีที่แล้ว

      @@HowToFAQ thankyou for your quick response Samuel!!!.
      I tried substring but it isn't working.
      Am I missing something??. Apologies as I am very new to this

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there,
      So let me explain. ("OK",[b'1']) is a tuple hence you can use indexes to extract the binary values. Don't use substring methods because it is incorrect.
      Response = ("ok",[b'1'])
      message_ids = Response[1] # [b'1']
      message_id = Response[1][0] # b'1'
      Keep in mind that the Response can contains a list of binary IDs as well for example.

    • @bhaskarsrivastava5654
      @bhaskarsrivastava5654 6 ปีที่แล้ว +1

      @@HowToFAQ got it, Thanks a lot :)

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      You're welcome, always happy to help!

  • @jagslab
    @jagslab 3 ปีที่แล้ว

    GOAT tysm

  • @ranjitsembeddedsolutions7041
    @ranjitsembeddedsolutions7041 6 ปีที่แล้ว

    hello bro im checking only body of gmail and getting some error like
    AttributeError: 'module' object has no attribute 'message_from_bytes'
    please help me on this

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there, could you post you're full code ?
      Many thanks
      Samuel

    • @ranjitsembeddedsolutions7041
      @ranjitsembeddedsolutions7041 6 ปีที่แล้ว

      hello bro here is my code
      import imaplib, email
      user = '*********@gmail.com'
      password = '**********
      imap_url = 'imap.gmail.com'
      def get_body(msg):
      if msg.is_multipart():
      return get_body(msg.get_payload(0))
      else:
      return msg.get_payload(None,True)
      con = imaplib.IMAP4_SSL(imap_url)
      con.login(user,password)
      con.select('INBOX')
      result, data = con.fetch(b'3','(RFC822)')
      raw = email.message_from_bytes(data[0][1])
      print(get_body(raw))

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there, in python 2.7 message_from_bytes doesn't exist you will have to use message_from_string. In python 3 they introduced message_from_bytes.
      Many thanks
      Samuel

    • @ranjitsembeddedsolutions7041
      @ranjitsembeddedsolutions7041 6 ปีที่แล้ว

      Thanks samuel fro your quick response it works by changing to "string"
      but problem is that im getting body of mail which is 3 years old.

  • @gerardkodjo9675
    @gerardkodjo9675 5 ปีที่แล้ว

    nice work Sir
    please i want to list and save all inbox message in database with python
    can you help me

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      Hi there,
      If this something you want to do frequently then using Python is an alright approach but consider using Thunderbird instead since it can provide a lot of power in terms of export emails and more them etc.
      Many thanks
      Samuel

  • @majbarrosleite5442
    @majbarrosleite5442 5 ปีที่แล้ว

    Great explanation, however I would like to know how to get rid of the following error:
    'imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว

      You need enable. Less secure app in Gmail

    • @varuntaneja4654
      @varuntaneja4654 4 ปีที่แล้ว

      @@HowToFAQ still getting the same error

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Check the Gmail Account for any security messages. Google normal flags up any IMAP of SMTP connection as a security issue.

  • @felipedeleon7575
    @felipedeleon7575 4 ปีที่แล้ว

    Any idea of how to click in a specific link inside an e-mail?

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Hi Felipe de Leon,
      What exactly do mean by clicking the link?
      Many thanks
      Samuel

    • @felipedeleon7575
      @felipedeleon7575 4 ปีที่แล้ว +1

      @@HowToFAQ hey Samuel,
      Every day I receive the same e-mail, which contains a different link. This link basically downloads a file. Instead of the file being an attachment in the e-mail, it comes as a link.
      Downloading this file would allow me a second phase of this automation idea - cause it's basically a CSV - but not as attachment in the e-mail.
      Let me know your thoughts.
      Thanks

  • @threepwoot8942
    @threepwoot8942 4 ปีที่แล้ว

    can hardly read the code without going fullscreen and its pixelated as hell in 1080p :(

  • @saeedalipoor5733
    @saeedalipoor5733 5 ปีที่แล้ว

    how i can fetch email by tag or forwarder ! not by id .

  • @pymailapp2254
    @pymailapp2254 6 ปีที่แล้ว

    Hey Very Nice Video. Can you help how to fetch only the last message recieved?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +pymail app On each inbox when selected it returns the size of the inbox. The message is of the latest email will be equal to the inbox size.

    • @pymailapp2254
      @pymailapp2254 6 ปีที่แล้ว

      Thanks. How to get the Inbox size into a variable?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +pymail app Hi there, when you select the inbox the inbox size is returned along with whether the request was successful. result, data = con.select("INBOX")
      data will be the message is in byte form. Perform the fetch using data as the message id.
      Hope this helps
      Many thanks
      Samuel

    • @pymailapp2254
      @pymailapp2254 6 ปีที่แล้ว

      It worked!

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +pymail app That's Great!

  • @surjosoft9688
    @surjosoft9688 6 ปีที่แล้ว +1

    can you help me read Receive Gmail mail using vb6.0?

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there,
      The basic concepts are the same.
      Here are some useful resources:
      IMAP:
      www.example-code.com/vb/imap.asp
      SMTP: code.msdn.microsoft.com/VBSMTPSendEmail-bdcec608
      And another handy reference: www.tutorialspoint.com/vb.net/vb.net_send_email.htm
      Hope this helps
      Many thanks
      Samuel

  • @Infiniti.151
    @Infiniti.151 5 ปีที่แล้ว +2

    awesome guide! I'm also writing a code to download attachments in python. I want to download attachments from a particular email for a particular time frame, for ex. for the email 'marketing@arkinfo.co.in', search name 'ARK Marketing Team' for the time period Nov 1 2018 to Dec 1 2018. How to put these parameters in con.select()? Your help would be very valuable. thanks

  • @KereellOlorin
    @KereellOlorin 2 ปีที่แล้ว

    Does anyone can see what happens on the screen? Dude ..., maybe tutorial is nice but it's hard to see

  • @richardjoy8925
    @richardjoy8925 6 ปีที่แล้ว

    is it possible to forward an email without downloading the contents.

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      +Richard Joy I think you have to download the email then forward it but there is no need to decode it. It may be the case that using the Gmail API you can forward an email without downloading it. However in python 3 you would use a combination of SMTP and imap to do this.
      If you are downloading a lot of emails and forwarding them I recommend setting it up on multi threads so that you can easily download small emails and forward them whilst the large emails are downloading .
      What are you forwarding ?
      Many thanks
      Samuel

    • @richardjoy8925
      @richardjoy8925 6 ปีที่แล้ว

      multi threading is fine, still i have to download it."What are you forwarding ?" - i was just messing around with this code ..i just asked out of curiosity. BTW your tutorials are really good, keep it up👌

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว +1

      +Richard Joy Thanks, I try my best to help others!
      You could look in to the GMAIL API, which is another method of interfacing with emails on Gmail. I imagine you could forward an image with it given ID without downloading it contents and also meaning the bulk of the processing power is used on Google's server.
      Many thanks
      Samuel

  • @wmu971
    @wmu971 4 ปีที่แล้ว

    The code is very blurry how can I see it clearly please?

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Hi Ranya,
      You could try watching on a laptop or desktop with the quality set to 1080p.
      Many thanks
      Samuel

  • @imagineexistance4538
    @imagineexistance4538 5 ปีที่แล้ว

    Any way to find sender?

  • @RajKumar-sh1wu
    @RajKumar-sh1wu 5 ปีที่แล้ว

    sir why there is no provision of commenting

  • @YogawithJankei
    @YogawithJankei 6 ปีที่แล้ว

    Hi,
    When I run the script, I get an error -
    imaplib.IMAP4.error: LOGIN command error: BAD [b' Failed to parse your command']
    How do I resolve this? Please help.
    Thanks.

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Hi there,
      This appears when your imap url is invalid or you login (username or password) is incorrect or even if you try to select an inbox in the wrong format. Not this: s.select("[Gmail]/All Mail") but this is correct: s.select('"[Gmail]/All Mail"') (Note the use of two sets of quotation marks)
      Hope this helps!
      Many thanks
      Samuel

    • @YogawithJankei
      @YogawithJankei 6 ปีที่แล้ว

      Hi,
      How do I check whether the imap url is invalid?
      My login details are correct.
      This is the script I'm trying to run -
      import email, imaplib
      username = ' '
      password = ' '
      mail = imaplib.IMAP4_SSL("imap.gmail.com")
      mail.login(username, password)
      I get the same error. What do i do now?
      Thanks.

    • @HowToFAQ
      @HowToFAQ  6 ปีที่แล้ว

      Try pinging it in command prompt to see if responds.

    • @YogawithJankei
      @YogawithJankei 6 ปีที่แล้ว

      I am using Python 3.5.

    • @YogawithJankei
      @YogawithJankei 6 ปีที่แล้ว

      Okay it does respond saying ' email authenticated ( Success) '
      How do i make it run in the shell? Because this script is part of a bigger script.

  • @ananyachakraborty2113
    @ananyachakraborty2113 5 ปีที่แล้ว

    I got this error
    AttributeError: 'module' object has no attribute 'message_from_bytes'

    • @TravisDDr
      @TravisDDr 4 ปีที่แล้ว

      did you solved it?

  • @vallabhchugh976
    @vallabhchugh976 4 ปีที่แล้ว +1

    my get body would take the whole html and not the just the body

    • @HowToFAQ
      @HowToFAQ  4 ปีที่แล้ว

      Hi there,
      Emails can be sent in HTML or plain text or both. You can use modules like html2text if the email is only in HTML and this you can extract the raw plain text.
      Another method would be to use a HTML parser and extract the key information your need from the email.
      Hope this helps!
      Many thanks
      Samuel

    • @vallabhchugh2075
      @vallabhchugh2075 4 ปีที่แล้ว

      @@HowToFAQ Hey thankyou for replying (that was from my another account)
      My question was not that.
      I was trying to say the get_body function does not WORK.it returns the whole html,not just the body.
      I think this can be a version issue.
      I ran your github repo code,can you run again and check

  • @rafaelveloso8409
    @rafaelveloso8409 4 ปีที่แล้ว

    The resolution is horrible, can barely see what are you writing

  • @bhupeshsahu384
    @bhupeshsahu384 5 ปีที่แล้ว

    Says credentials are not right, despite having checked it multiple times.

    • @HowToFAQ
      @HowToFAQ  5 ปีที่แล้ว +1

      Hi there, I would recommend trying to enable "Less Secure Apps" on Gmail.
      Many thanks
      Samuel

    • @bhupeshsahu384
      @bhupeshsahu384 5 ปีที่แล้ว

      @@HowToFAQ wow, incredible response time. You have surely earned yourself a die-hard fan today (irrespective of whether this works or not) :D Thanks Samuel

    • @bhupeshsahu384
      @bhupeshsahu384 5 ปีที่แล้ว

      IT WORKED, thanks man.. I am using PyCharm. How do I get the second screen in place (the one on the right). Apologies for such basic questions.

  • @gravitchaudhary2527
    @gravitchaudhary2527 4 ปีที่แล้ว

    eyesight should be 6/6 to read the codes.

  • @chimerablack4913
    @chimerablack4913 4 ปีที่แล้ว

    fonts too small bruv

  • @ИванПетров-д3в
    @ИванПетров-д3в 5 ปีที่แล้ว

    bro could you choose lesser font. This one is too big.

    • @RajKumar-sh1wu
      @RajKumar-sh1wu 5 ปีที่แล้ว

      exactly bro...i do feel the same

  • @babajee4644
    @babajee4644 6 ปีที่แล้ว

    hello sir how to get the code file of this

  • @boringchannel6313
    @boringchannel6313 4 ปีที่แล้ว

    font size : nano

  • @TheEbbemonster
    @TheEbbemonster 5 ปีที่แล้ว

    Make text readable