How To Send an Email in Python With Attachments Easy for Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024
  • How To Send an Email in Python With Attachments Easy for Beginners
    Code (Github): github.com/sam...
    Signup to my Python Developers Guide to Learning Python: eepurl.com/c06OgL
    Subscribe: https//bit.ly/SubFreeNow
    Hi Everyone,
    In this video, I explain in depth how to send an email in Python via SMTP protocol. I show a nice example using a Gmail's SMTP server.
    CC contribution Link: www.youtube.com...

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

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

    Thank you man. It's 2am where I'm at and I'm working on a little project and then I thought, "What if I can add an email function to it?" And I found your video. It's great code. Writing it in a simple way then changing to becoming more complex it's great. You've got a new sub.

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

      Thanks so much! It always great to know people are enjoying the content! Stay tuned for more content...

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

    Thanks for the video. First time I ran the code I encountered an error, so I changed
    server = smtplib.SMTP('smtp.gmail.com', 587)
    to
    server = smtplib.SMTP('smtp.gmail.com:587')
    and it ran just fine.
    What I'm going to do now is modify it so that it loops its way through a folder of photos, sending one each hour to a friend. Cheers for your time and effort.

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

      +Michael Hudson Hi Michael, I am familiar with both syntaxes working, so I haven't had errors with it but I guess possibly others may experience similar issues so thanks for pointing it out!
      Nice idea of sending a photo to a friend every hour !
      Many thanks
      Samuel

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

    Thanks. I have finally completed it, after checking many youtube channels.

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

      You're welcome!

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

    This guide was exactly what I needed.

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

    First of all i would like to thank you, very useful video. i am working on Raspberry Project which is "a smart walking stick for blind" attache with GPS.
    i want the system to be able to longitude and latitude to a relative through mail. thanks again

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

      Sounds cool! Glad you liked the video

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

    Thank you! This was very helpful. I've successfully used the code to power my website's contact form.

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

      Cool, nice one!

  • @ankita-4474
    @ankita-4474 6 ปีที่แล้ว +3

    VERY MUCH HELPFUL. THANKS A TON!!!!
    Just more explanation about the code are needed. All commands worked for me

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

      You're welcome!

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

    Thank you for simplifying. I followed your instructions and it worked as expected. Awesome!

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

    Great video, thank you. You have explained in 20 mins what I tried doing for hours haha.

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

      +Bob Capstone You're welcome!
      What project you working on?

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

    Best thing happened to me in lockdown so far...Thank you so much for the best explanation....Helped alot.Cheers 👍🏻🤘

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

      😀👍 You're welcome! Let us know what content you would like to see on the channel.

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

      @@HowToFAQ I just enjoyed your explanation and got cleared with my doubt's.
      If you can please put python tutorial episodes that would be great.
      Thank you 😎

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

      Thanks bro HowToFAQ, I’ve been trying to add a link to the code. But it’s been tough. Please how can I add an HTML link to the code

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

    First off, I want to thank you. I am on my senior design project and you saved me and my entire team from miserably failing. one question though, I am using the algorithm as a function inside a while loop that uses a thermal sensor and motion sensor to detect wildlife. The send_email function takes the picture name as an argument from the while loop and passes it as the filename to attach to the email. However I noticed that having the function inside basically stops the loop UNTIL I receive the picture in the recipient email. Is there anything I need to remove from your code or something I can do to keep the loop going and send the pictures in the background?

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

    I made a keylogger that records key strokes and saved the key strokes to a file.log. Now all i need to do is to get my victim to download it along with the send_email.py thing and get it to run. If i can do that i can get emails on what my victim is typing because i'm getting email attachments when the thing is running. Thanks you helped ALOT!

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

      wassup, could you send me code of that keylogger ?
      I wanted to make keylogger.

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

      thx

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

    Brilliant! I am going to use to email pictures of humming birds when they drink from our outdoor feeders (using a PIR motion sensor). Very thankful for this tutorial :)

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

      That's so cool! Would love to hear more about it.

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

    Great video! How can I adapt it to send routinely at a certain time? For example once a week on a particular day? Thanks!

    • @dr.chaosyt2578
      @dr.chaosyt2578 4 ปีที่แล้ว

      You know, that is a really good question

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

    I specify full path of the attachment because it is key to my project. But then when I send email, it displays the entire path of the file and not just the File name itself, what should I do?

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

    finally a working tutorial.. thankss for explaining things in easy manner

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

    thank you for your work.
    message = 'how about responding to people"s emails?' for x in message: print server.sendmail(carta_user, carta_send, message)
    im trying to make a loop will this work?

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

    Please help me. when i run this program it return error stating gaierror:[errno 11004] getaddrinfo failed

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

    Worked for me. Thanks. ur awesome.

  • @priyansh.j97
    @priyansh.j97 5 ปีที่แล้ว +2

    Thank You HowToFAQ, you have restored the faith in humanity by making this video! Loved it, It worked! :)

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

    Thank you so much you explained almost each step. I am very glad

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

    Thank you very much for this tutorial.
    I have a query on attaching a pdf document to the mail which has the data in JSON format where the JSON format is extracted from API.
    Can i get any hint?

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

    Thanks alot for your great video. Could you please let me know why I could not receive the attached file while I can see my text body? Thank you!

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

      Hi there,
      Double your code includes the correct filename of your file and actually attached that file to the email.
      Many thanks
      Samuel

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

      HowToFAQ it’s giving me errors. SMTP authentication error. Please help what can I do on my sublime text. It was working properly before.

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

    Hey thanks man, just getting into python and its nice to see something explained so well. Also good how you start simple and then work up to a more robust email app. Works great!

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

      +Nicholas Barning Thanks glad you found it useful!

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

      +Nicholas Barning I plan to do more Python videos so stay tuned!

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

    Thank you so much, I've been trying and looking around for a solution for forever now and this works!

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

      You're welcome so glad it helped!

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

    Thank you very much, this video helped me a lot !!!

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

    Awesome video thank you.
    How would you include an email signature at the end of the email that contains an image (perhaps a company logo or so) using python? Thanks again

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

    AWESOME == THIS is EXACTLY what I was looking for .... Thank you very Much !!!!!

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

      You're most welcome

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

    ​@HowToFAQ hai great to toturial. but want to ask you how to send attachment in folder such as attach all file in folder D:\Document and what ever inside the folder will send out inside email. appreciate if you can help.

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

    Thank you sir...perfect solution for me

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

    Awesome man.. just needed this.

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

    Thank You So Mush. Jajakalla Khairan...

  • @ofcdune
    @ofcdune 7 ปีที่แล้ว +14

    What if I want to send my email to more than one user? for example: a newsletter?
    great video btw.

    • @HowToFAQ
      @HowToFAQ  7 ปีที่แล้ว +16

      +TheComputerNerd Hi there,
      You would need to use the MIMEMultipart
      E.g....
      msg = MIMEMultipart()
      msg['Subject'] = 'Your email Subject'
      msg['From'] = 'your email'
      msg['To'] = 'recipient1@gmail.com, recipient2@gmail.com, reciptient2@gmail.com'
      Note the use of the comma between recipient emails.
      This also works the same with Cc and Bcc
      msg['Cc'] = 'recipient1@gmail.com, recipient2@gmail.com, reciptient2@gmail.com'
      msg['Bcc'] = 'recipient1@gmail.com, recipient2@gmail.com, reciptient2@gmail.com'
      Hope you find this helpful!
      Thanks for the excellent questions!

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

      Thank you HowToFaq for this very detailed answer. it helped me a lot ;)

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

      +TheComputerNerd No problem! Remember to get subscribed!

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

      Hey Sam, thanks for the awesome video. Pretty much the same question as asked above. I am trying to send a mail to a group of friends. What I realised was that when I have a list of email addresses only the first person in the list seems to receive it. For example lets say I am trying to send this mail to 3 people 'p1@gmail.com,p2@gmail.com,p3@gmail.com' only p1@gmail.com seems to receive it. However if I change the order in the script for the second run to lets say 'p3@gmail.com,p2@gmail.com,p1@gmail.com' p3@gmail.com receives this file but also do see the mail that should have come the first time is also in the tread of this second mail. Not sure if this makes sense but could you please help on this. Thanks..

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

      Hi there, could you post your code ?

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

    Amazing tutorial! I'm currently working on a Raspberry Pi Surveillance project. I'm using a PIR motion sensor to determine if someone is in a specific area, and if so take a picture of them and then send it to my email. Should help with thieving roommates raiding the fridge

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

      Sounds very intriguing, be sure to us updated on progress on the project.
      Many thanks
      Samuel

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

      @@HowToFAQ Current update: My PiCamera finally shipped, and in place of the PIR motion sensor (which should be arriving tomorrow), I have used a physical button. Referencing your guys' code, I put it into a function inside a try block. If no errors occur, the function will return true, exceptions return false. I have a green and red LED light up accordingly upon success or failure within the main method. I also have a small function which takes the picture and stores it in the directory of the python file. I use that directory location as the attachment. Then from there, I run the program, it waits for a button push, takes the picture, goes into sending the email, if success the green led comes on, and then that's it! :) Once the PIR motion sensor comes, all I need to do is replace the "wait for button press" with "wait for motion". So far everything works as intended!

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

      @@HowToFAQ Project finished :) Works great! Github repo: github.com/NicholasAMills/RPiSurveillanceSystem

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

    the setting allow less secure are no longer available, do you have other option?

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

    Hi
    It throws me below error for line server = smtplib.SMTP('smtp.gmail.com',587)
    Error: getaddrinfo() argument 2 must be integer or string
    I have enabled low secure apps also. It would be great if anyone could help?

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

    Hi there thank you so much but you have not defined the path in the code from where python will look for the attachments can you please let me know the code for the path thank you once again .

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

    hey..! there was doesn`t have any error but output no...please help me

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

    hey i m getting an error while sending the attachment
    as "SMTPServerDisconnected : Connection unexpectedly closed"
    while I m able to execute simple text sending code

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

    Great video. But I have a question that how can I attach more attachment at one time?

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

    Thank you very much for you video. It is very good. I am new in python but is very clear and is well explained as I can undrestand it. Thank you very much.

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

      I am so glad you found the video helpful. Any suggestions for videos you'd find helpful in future ?

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

      ​@@HowToFAQ It can be made an python app that read my mailbox making an filter with input words that I set : for example the mails that I receive for my electricity supplier, or a frend that I expect an e-mail(the words can be: invoice, address, or others)? Thanks for your feedback!

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

    Hello. Can I use these to send emails to Outlook?

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

    Thanks, this worked for me, however I had an email forwarder that shows my business domain name when I send with my regular gmail address. Is there any way to get that back?

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

    Much appreciated video! I need to send email subscriber newsletter to FB ,YT and other platform . What is the best way to approach this? Any ideas?

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

      Interesting...
      This sounds difficult because many of the sites you mentioned no longer allow you to identify users by email.
      However, if you created an application on each platform that a user could subscribe to then you could send messages to them.
      Data protection and privacy is a growing facet in the social media market so user consent is becoming more of a requirement.
      In your case the correct solution would be to try and get users to authenticate in your application allowing you to access the information and send them messages on those platforms.
      Many thanks
      Samuel

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

    Great Video - very well done and detailed. Thanks!

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

      +Robert Petrlak Thanks, glad you found it useful! Any suggestions for future tutorials ?

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

    Hey! Could you tell me what Error will be raised if I run the program and there's no internet connection?

  • @AlexandreRodrigues-wq9hi
    @AlexandreRodrigues-wq9hi 5 ปีที่แล้ว

    Hi, thanks for this video, that's exactly what I'm looking for ! But by using your code I have an issue, "'list' object has no attribute 'encode'" do you know why ? It comes from the line "text = msg.as_string()"

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

      check if you need to install any module.

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

      or .. check if you are importing all modules

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

    This project is very helpful 👍
    But i want to send large attached how can I send large file using gmail which when we send it manually it needs to upload on drive then we send it plz help please

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

      Hi there,
      I'm glad you've found it helpful so far. I recommend checking out my video on Google Drive API - th-cam.com/video/9OYYgJUAw-w/w-d-xo.html . In the video I show how to upload files. You can obtain a shareable link from the "webViewLink" property in the return JSON for the Google Drive File that you could then include in an email to send to someone so they could access it.
      Documentation for Google Drive API: developers.google.com/drive/api/v3/reference/files
      Many thanks
      Samuel

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

    OMG FINALLY A WORKING TUTORIAL, THANK YOU!

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

      Hi there, you're welcome feel free to check out some my other tutorials.
      Many thanks
      Samuel

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

      You replied so fast! I can't thank you enough, because i was searching the internet for proper code or tutorial and only yours had worked! Thank you!

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

    Brother you are a genius!!!

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

    Thanks, a lot for this great sample of code. Do you have any idea how i can avoid changing the attachment filename? It is set to ATT000001.bin by default and i want to keep the original filename.

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

    Hi! This project is AMAZING! I wanted to do a similar project by sending an image and I am using RaspberryPi 3, similarly using python. would I do the same commands? also, I wanted the message to be sent automatically like every minute, can I do that? thank you so much.

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

      Hi there,
      Yes, these commands will be exactly the same on your Raspberry Pi 3. Just check the version Python. These commands are for Python 3.
      To sent a message every minute automatically I would use a crontab.
      There is a guide here: www.raspberrypi.org/documentation/linux/usage/cron.md
      Many thanks
      Samuel

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

      HowToFAQ OMYGOSH! Thank you soo Samuel!! 😍

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

      @@HowToFAQ by the way, if I input all these codes on my Raspi 3, I'll follow the same process, right? :)

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

      Yeah, that's right!

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

      HowToFAQ yes I am using Raspi 3 B+, would that matter? Because I inputed the same commands unfortunately, I won’t run :( I tried it a couple times but I still get the same result. ☹️

  • @ameenmohammed1843
    @ameenmohammed1843 7 ปีที่แล้ว

    Hi could you please tell me how to send a text email with attachment using tls/ssl, and without using smtplib.

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

    I made an exe file of this script to run from other workstation, however the exe is not sending email from other laptops. Can you help with is problem

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

    is there any method to send an email with "On Behalf Of" someone address in from address by using python-smtplib?

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

    Hello,
    All code is working fine I received file through mail. But file shows 'noname' and could not open it. What's the mistake?

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

    Anyone have advice on how to format the name of a .pdf -- when my recipient views the email, the attachment is called 'noname' and uses a weird difficult to read file type. Any advice?

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

    Traceback (most recent call last):
    File "C:/Users/MyName/Documents/send_email.py", line 21, in
    server.sendmail(email_user,email_send,text)
    NameError: name 'text' is not defined

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

    Great video! I have a couple of questions:
    1) I want to send to multiple recipients. All of the emails (thousands) are in an excel sheet. How can I get this script to read the .csv file and extract the emails?
    2) I have an alias email address that I sometimes use, it is a private email server, not Gmail. How could I send from that email? Usually, ​I go into my Gmail​ and just select which address I want to send from.

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

      Hi there, so you will need to first make a function that reads a csv file and obtains the relevant information this can be down by delimiting by a comma and new line. Now you can send the email. If you have to send it from a different email it would be best to sort it to different lists/ dictionaries. Then just login separately through a function.
      There many csv tutorials online and logging in again is quite easy.
      Many thanks
      Samuel

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

      +Noel D'Souza Yeah I agree pandas is a good solution

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

      I'll look into it. Thanks

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

    Thanks buddy it's working. But I have some query regarding an attachment. Could You tell me how to send a video?

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

      Hi James,
      Sending a video over 25MB is not possible since most email services like Gmail have a message size cap of 25MB. You can upload to Google drive using the drive API and then send the link.
      Many thanks
      Samuel

  • @algoholic-pro
    @algoholic-pro 5 ปีที่แล้ว

    Thank you sir ,You simplified my work by a ton

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

      Glad to have helped. You're welcome

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

    Somebody help me with this error that i get trying to execute the program'
    Traceback (most recent call last):
    File "functions.py", line 22, in
    attachment =open(filename,'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'cow.txt'

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

    Amazing video,but is there any way i could delete the text file after sending it?

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

    does it work with PIl- Images as well?

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

    hi...if I want to send more than 1 files is that possible?

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

    Thanks a lot for the video,man !

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

      You're welcome!

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

    Thanks for a great vid! I get en error due to the extra paranteses after "part.set_payload(attachment).read())", any clues to what misstake I made?

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

      +Anders Erlend Idås Hi there,
      Can you post your full section of code where you send the email ?
      Then I may be able to assist you.

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

      Thanks for the fast reply:
      import smtplib
      from email.mime.text import MIMEText
      from email.mime.multipart import MIMEMultipart
      from email.mime.base import MIMEBase
      from email import encoders
      me=""
      you=input("Your mail:")
      topic=input("Topic")
      msg=MIMEMultipart()
      msg["From"]=me
      msg["To"]=you
      msg["Subject"]=topic
      body = "Hovedtekst"
      msg.attach(MIMEText(body,"plain"))
      filename="test.pptx"
      attachment = open(filename, "rb")
      part=MIMEBase("application", "octet-stream")
      part.set_payload(attachment).read())
      encoders.encode_base64(part)
      part.add_header(Topic,"attachment;filename= ", filename)
      msg.attach(part)
      text=msg.as_string()
      mail=smtplib.SMTP("smtp.gmail.com",587)
      mail.ehlo()
      mail.starttls()
      mail.login("","")
      mail.sendmail("","",text)
      mail.close

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

      Hi there,
      Sorry for the wait I was just looking at your code and I think the code below should work:
      #I changed a few things and now it works fine for me.
      import smtplib
      from email.mime.text import MIMEText
      from email.mime.multipart import MIMEMultipart
      from email.mime.base import MIMEBase
      from email import encoders
      email_user = 'your_email'
      email_password = 'your_password'
      email_send = input('Your email:')
      subject = input('subject: ')
      msg = MIMEMultipart()
      msg['From'] = email_user
      msg['To'] = email_send
      msg['Subject'] = subject
      body = 'Hovedtekst'
      msg.attach(MIMEText(body,'plain'))
      filename='test.pptx'
      attachment =open(filename,'rb')
      part = MIMEBase('application','octet-stream')
      #You didn't have the overall parentheses here.
      part.set_payload((attachment).read())
      encoders.encode_base64(part)
      #Topic before wasn't defined.
      #Best to use Content-Disposition for attachments
      part.add_header('Content-Disposition',"attachment; filename= "+filename)
      msg.attach(part)
      text = msg.as_string()
      server = smtplib.SMTP('smtp.gmail.com',587)
      server.starttls()
      server.login(email_user,email_password)
      #tls isn't always supported.
      #server.starttls()
      server.sendmail(email_user,email_send,text)
      server.quit()

    • @anderserlendidas488
      @anderserlendidas488 7 ปีที่แล้ว

      Thanks! that worked perfectly!

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

    Great video. However, I wanted to know - What if you have multiple attachments that have different file names generated every day. How would the email script capture the new file names from the particular location and automatically send them every day?

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

      Hi there,
      You could use the os module in python to get a lists of the filename in a given directory and then iterate through these file paths attaching each one then sending the email. If you only want to the files that are new to the directory since the last time the script ran you could make a timestamp (a text file storing the last runtime of script) and then only get files created/modified after this timestamp.
      This is most likely the easiest and quickest method!
      Hope this helps.
      Many thanks
      Samuel

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

      We try it out and see how it goes. Thanks a lot

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

      Would you know why CSV attachments would be received as a ".bin" file? After sending the attachment, it is received as ATT00001.bin. When you open with notepad, you can actually see the contents of the CSV file.

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

      It may be the case that you didn't correctly assign the attachments filename for the email. 'ATT00001.bin' may be a default name.
      Many thanks
      Samuel

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

    how did you sent an attachment without just defining the path..cause i am unable to send attachment from the same program,kindly help asap

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

    Still relevant. My Thanks!

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

    Hey, what if I want to control all these processes from the browser?

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

    Very interesting !!!!!!!

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

    Nice video sir but if I want to send detected face goes to my Gmail using python code how I can send it

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

    This setting is not available for accounts with 2-Step Verification enabled. :/ gmail whyyyy

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

    hi is there anyway I can add the entire folder as a attachment?.

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

    Hello can I have a question? is it possible to set a timer? and make it send for example every 1 hour?

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

      Yeah you could setup a while 1 loop with a sleep(3600) then run the function. That would run every hour

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

      Thanks a lot! Can I run it with only background process?

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

      Technically you can

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

      Sounds fishy " I wanna run a script that sends an email a lot of times over and over in the background "

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

    useful indeed! thanks

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

    Thanks for the great video bro i have tried lot of other tutorial but only this works for me.
    Actually i'm working on my collage project which will capture image from door camera and send it to gmail and depending on replay YES or NO door will open.
    Now then replay from gmail part is remaining can you please help on this.
    how to check new gmail from inbox and toggle gpio according to replay.

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

      Hi there, I'm so glad this helped you! Sounds like an interesting project... Any other programming tutorials you would find helpful?

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

      i need your help in " how to check new gmail from inbox and toggle gpio according to replay."

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

    Hey man! Excellent short tutorial video on sending email using Python - thanks a ton, this really helps.. subscribing for more good stuff.. Regards.

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

      You're welcome, I love to make tutorials that help people learn. Any tutorials you would like to see ?

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

      Hey !! Thanks for asking - if possible make some videos on pandas data frame - example downloading excel attachment from email box and then parsing its data.

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

      where to save document.txt?

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

    really useful, thanks a lot.

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

      You're welcome!

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

    This video was so helpful! The instruction was easy to understand for beginners

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

      Hi Curtis,
      That's great! Are just getting into programming then?

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

      I get that error : module 'smtplib' has no attribute 'SMTP' please help thank you

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

      Hi there,
      I would recommend reinstalling the 'smtplib' module.
      Many thanks
      Samuel

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

      Where can i do that?

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

      thanks it works!!!

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

    Thank you very much HowToFAQ

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

    can we create drafts in gmail using Python?

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

    Thanks you so much.... It is very Useful to us.

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

      You're welcome

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

    I saved mine as 'email.py'... how do I sort that out?! As you said, can't get the smtplib to work at all!
    Thanks

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

      Hi there,
      Rename the file name to something that's not 'email.py' since it conflicts with the python email module which is imported by smtplib.
      Many thanks
      Samuel

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

    Very useful !! Thanks a lot ..

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

      Thanks :)

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

    thanks @HowToFAQ for nice explanation ,but while running this code I am encountering the below error. TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time
    , or established connection failed because connected host has failed to respond
    Along with this I am getting a mail from gmail for "Critical security alert"

  • @RajeevKumar-zj1nk
    @RajeevKumar-zj1nk 6 ปีที่แล้ว

    Thanks for the information and video is helpful.

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

      You're welcome, glad you found it useful!

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

    how will it find the attachment without specifying the path?
    Great video btw
    Didnt understand only that point

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

      I am having this issue as well. I am getting error No such file or directory. (Meaning its not finding the path.)

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

      @@rudebwoynau replace / with \

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

    great video, your explanations are the clearest i've seen for this subject, thank you
    +1sub

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

      Thank you, you are welcome!
      Much appreciated.
      Many thanks
      Samuel

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

    Thanks mate... Just a question.. I'd like to have user prompt for password on execution. I can do that but how can I make sure that when user types the password its hidden.

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

      Hi there, if you want to hide the users password when they enter it you can use:
      import getpass
      p = getpass.getpass('Password: ')
      #This hides user input
      I would recommend checking out my video on the GMAIL API if you want to be more elaborate when sending emails. Using the gmail api you can get the user to login via gmail.

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

      Mate.. I did that but when I enter the password its still visible.

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

      Replace input("password:") with getpass.getpass("password:")

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

      This is exactly what I tried. see below
      passw = getpass.getpass('Please enter your password: ')
      Output----
      Warning (from warnings module):
      File "C:\Python27\lib\getpass.py", line 92
      return fallback_getpass(prompt, stream)
      GetPassWarning: Can not control echo on the terminal.
      Warning: Password input may be echoed.
      Please enter your password: 111111

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

    thanks so helpful !

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

    Which libraires to install ?

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

    can you help me out? i manage to sent the email but the attachment is empty. i tried sending .pptx, .jpg, and .txt but no luck.

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

      Hi there,
      Post your code and I will see if there are any problems...
      It sounds like you are either encoding it incorrectly or not at all.
      Many thanks
      Samuel

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

    Would that work if I want to send .zip files ?

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

    Hi there,
    I was wondering is this also compatible using Microsoft Outlook?

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

      +Christopher Kim Technically it is if you find out the IMAP server URL and port

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

      Awesome thank you
      I am actually trying to create an automatic email listing for my startup and I really don't want to send it out manually or pay for 3rd party services
      Are there any packages you may reccomend?

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

      +Christopher Kim correction I made a typo you need the SMTP URL and port in order to send emails. IMAP is for getting emails

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

      +Christopher Kim It really depends on the volume of emails services like Outlook and Gmail have upper bound limit I think it is 1000 a day for Gmail. Eventually you will most likely need to you a CRM (client relations management)

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

      Actually I am planning to send only 100 a day max lol

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

    Thanks dude ! Worked like a charm... :-)

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

      You're welcome, glad it helped! Any other videos that you would interested in seeing ?

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

      I'm good for now. Working on a webshop for a festival. I needed the option of sending emails in order to send the tickets to the people that bought them online.
      Next step is to implement the payments (not at all unimportant :-) )
      In Holland we use "Molly" for that... and / or Paypall

  • @anon-sl4vp
    @anon-sl4vp 6 ปีที่แล้ว

    nice vid bro :) good stuff

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

      Cheers! Any suggestions for future videos ?

    • @anon-sl4vp
      @anon-sl4vp 6 ปีที่แล้ว

      let me have a think and ill let uno m8 :)

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

    I am getting an error "No Connection could be made because the target machine actively refused it"
    Any inputs ?

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

    Great video!