How to Send Emails with Python: Plain text, HTML with attachments

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

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

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

    From May 30, 2022, ​​the Less secure app access setting is no longer available for Gmail. But it might be available for other mail service providers.
    To fix the problems with our tutorial on Gmail, please set up an App Password. The general steps are go to your Google Account -> Security -> turn on 2-Step Verification -> Security -> set up an App password.
    For details, please visit support.google.com/accounts/answer/185833.
    Then, you can use such a password to send emails in Python.

  • @nejhadehyarollahi4735
    @nejhadehyarollahi4735 11 หลายเดือนก่อน +1

    sublime tutorial, really helpful. thanks a lot!

  • @beatrizcaravina2674
    @beatrizcaravina2674 3 หลายเดือนก่อน

    Thank you SO MUCH. Amazing video!

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

    really clear and good explanation- Thank you very much.
    👋

  • @anurajms
    @anurajms ปีที่แล้ว

    thank you

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

    Amazing video! thanks a lot ;)

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

    Excelente video tutorial!! 🔝🔝🐍🐍

  • @bibybsa7921
    @bibybsa7921 ปีที่แล้ว

    Great tutorial.
    In my notebook, I am combining scrapping with selenium and pandas for using the data scrapped,
    With the gathered data I create a "summary" with a print() with some calculations and phrases.
    How can I send that print() by email as body?

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

      Hi Bibybsa, I haven't tried it myself. But I assume you can convert the 'summary' to a string and include it in the email body.

    • @bibybsa7921
      @bibybsa7921 ปีที่แล้ว

      @@justintodata I was too new and never used f-string. With that knowledge I could easily insert seaborn graphics and calculations as summary. Thanks a lot. In order to make the pandas dataframe be visible on the e-mail, I used tabulate with "html" format.
      If anyone sees this video, I think it will help.
      Thanks a lot for answering!

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

    Hello, how to add the path for sending attachments located in a different directory?

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

      Hi Santiago, you can simply replace 'filename' with the full path in the function

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

      Thanks a lot! I was very simple!@@justintodata

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

      @@justintodata And how to change the filename after replacing the fullpath? otherwise the filename in the e-mail goes as the full path

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

      @@brenogoulart8091 Hi Breno, do you mean you want to change the attachment file name? You'll have to play with this f-string. You can just grab part of the strings of the filename.
      f"attachment; filename= {filename}"

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

      @@justintodata Thanks a lot. Just created a filepath and filename variables in the function. Great video and support.

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

    nice video! Is there any way to have the script check whether the email was successfully sent ( or at least moved to the outbox)?
    Because my organization periodically requires a new login (with 2 factor authentication), and I need to know if my program actually sent the emails or not, and if not log the contents of the email somewhere else so I can send it later.

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

      Hi Pascal, I imagine you need to use your mailbox's API, there should be functions to check the outbox

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

    Great video. Do you know how to get python to read email attachments and store them in a storage bucket like GCP cloud storage?

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

      Hi Andy, it should be possible but we don't have experience with that so can't help much

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

    Hi great video super clear and easy to follow, one question: the add_header method... I don't quite understand the purpose of this, or how it really works, I read the documentation and I'm still slightly confused. The first field you put "content-disposition" what is the reason, and then I'm guessing the f"attachment is the string builder thing to make it cleaner? A little clarification would help, thank you much.

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

      Hi, you can read this doc for details developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

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

      @@justintodata Why thank you so much, that help cleared it up a lot, I was looking at the python docs, but this was much clearer. Again, you're super helpful thank you!

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

    it work but when when it send the email as spam any tips to fix it ?

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

      Hi valorant, I don't think Python can change this. This really depends on the rules of the receiver's mailbox, try using different subjects or content with no suspicious words

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

    Could you please make a video sending more than 1 mails with png or pdf attachment please

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

      Hi David, it's the same idea for different file types as attachments

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

      @@justintodata i tried but it's not going through can you please send me the codes for multi recipients with html

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

    work!

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

    I'm getting an error

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

      Can you please specify the error?

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

      @@justintodata hey! I got this one UnicodeEncodeError: 'ascii' codec can't encode character '\xf3' in position 17: ordinal not in range(128)

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

      @@jacquelinmontoyahidalgo6714 it seems like something in the text, you can either try changing it or set a different encoding