Java - How to Send an Email with Attachments

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ •

  • @dimadykyi6529
    @dimadykyi6529 3 роки тому +3

    Man, you have the best tutorial on the topic "how to send an email using Java". Thank you)

  • @JohnSmith-ej1qv
    @JohnSmith-ej1qv 3 роки тому +5

    Thanks WittCode! I like how you always explain everything!!!!

    • @WittCode
      @WittCode  3 роки тому +1

      Hey John! Thanks! That's my style haha 🤠

  • @robdeluksschmidt
    @robdeluksschmidt 3 роки тому +4

    What a perfect synopsis on this topic. Well done 10/10

  • @longkesh1971
    @longkesh1971 2 місяці тому

    Thank you so much. Short, simple explanation that worked for me once I set Gmail less secure app password setting in Gmail. Awesome.

    • @WittCode
      @WittCode  2 місяці тому

      Glad it helped! Thanks for watching!

  • @garimaanshum1416
    @garimaanshum1416 Рік тому +2

    Thank you very much for very informative learning video , i tried Enabling "Less Secure app access " but its showing message as " This setting is no longer available " please suggest an alternate

  • @oleksiishostak2563
    @oleksiishostak2563 2 роки тому +1

    Perfect explanation. Extremely helpful!

  • @andersontiban5356
    @andersontiban5356 2 роки тому

    man thank you for making videos, they are always easy to understand!

  • @nml4546
    @nml4546 2 роки тому +4

    the "Less secure..." in gmail has been disabled, so your program will no longerwork. If you have a solution, I'm sure we would all like to see it.

  • @JesusGonzalez-bq7kn
    @JesusGonzalez-bq7kn 2 роки тому

    Thanks for the walk through, it helped me out a lot. Just to point out the jar files you need is the javax.mail and activation.jar. Also the password you need to insert is not your regular password, it is a auto generated 13char that you can get in your google account under app passwords.

  • @shweta4102
    @shweta4102 2 роки тому

    exactly what I am looking for. Thank you so much. Very good explanation

  • @Dev-yz8qg
    @Dev-yz8qg Рік тому

    Hello! I have a question: What method should I use for attachment: setcontent() or setDataHandler?

  • @steve_lehr
    @steve_lehr 2 роки тому +1

    Google recently removed support for the Less Secure Apps option. Can you still use the gMail SMTP to send emails?

    • @crazytrucks1916
      @crazytrucks1916 Рік тому

      Yes, Now you can get from google password app.

  • @Anderzon1994
    @Anderzon1994 2 роки тому

    Thanks a lot for sharing your knowledge!

  • @engkuaimanzakwan2655
    @engkuaimanzakwan2655 3 роки тому +1

    Great video!

    • @WittCode
      @WittCode  3 роки тому

      Hey Engku thanks for watching and the support! 🤠

  • @princekachu1840
    @princekachu1840 2 роки тому +1

    Thanks for this! Can I request for the link of mail jar file

  • @baso8941
    @baso8941 2 роки тому

    is there any chance that you dont need to enable the less secure app setting on the account that will receive the email?

  • @goulenhaokip8536
    @goulenhaokip8536 Рік тому

    Will you please help me how to solve the “JPasswordField get deprecated”
    In Java swing JFrame project??
    🙏🙏🙏

  • @suelenfeijo5418
    @suelenfeijo5418 11 місяців тому

    very thanks!

  • @mutazhag240
    @mutazhag240 2 роки тому

    Thank you

  • @thiru4168
    @thiru4168 2 роки тому

    Sir, how to get response in sender side if button is sent in mail message is clicked in java mail api
    plz help sir

  • @joaquingutierrez5435
    @joaquingutierrez5435 3 роки тому

    how can i add signature and closing to mail?

  • @myosandikyaw5402
    @myosandikyaw5402 2 роки тому

    Thanks❤️

  • @vuacy
    @vuacy 3 роки тому

    i have always this exception: xception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
    at MyMail.main(MyMail.java:26) WHY???

    • @adamadamadde
      @adamadamadde 2 роки тому +1

      i get the same error: does anyone have a fix for this?

  • @prometheusli101
    @prometheusli101 3 роки тому

    awesome! very useful

    • @WittCode
      @WittCode  3 роки тому

      Hey good to hear from you again! Thanks for watching 🤠

    • @prometheusli101
      @prometheusli101 3 роки тому

      @@WittCode 😁😄

    • @prometheusli101
      @prometheusli101 3 роки тому

      ​@@WittCode if i try to send more than one email to same account in short time ,i would got time out error,is this normal?how can i solve this problem?

    • @WittCode
      @WittCode  3 роки тому

      @@prometheusli101 Hmmm... if it is a timeout error I believe you can specify timeout properties like the others in the video. Try adding these and changing the number value: properties.put("mail.smtp.timeout", "1000");
      properties.put("mail.smtp.connectiontimeout", "1000");
      properties.put("mail.smtp.writetimeout", "1000");

    • @prometheusli101
      @prometheusli101 3 роки тому

      @@WittCode thanks for your help,but this is not the solution,just ignore my question.i think this was google preset

  • @walterbalasoto7983
    @walterbalasoto7983 3 роки тому

    Thank Bro!

    • @WittCode
      @WittCode  3 роки тому

      Of course Walter! Thanks for watching! 😁

  • @ngoclinh3102
    @ngoclinh3102 2 роки тому

    thank you but how i can send a file in virtual machine

  • @Alain9-1
    @Alain9-1 3 роки тому

    is there a way to send multiple attachments more than 10 without repeating the mimepodypart for every single attachment

    • @WittCode
      @WittCode  3 роки тому +2

      Hey there Abdelouahid! I don't believe so but you could just make a method that does this to make things simpler! Make a method like attachMyFile() that just repeats the process of making a mimebodypart! Let me know if this helps! 😁

  •  3 роки тому

    hi WiitCode ; got "Cannot resolve method 'getInstance' in 'Session'" and so on 'Authenticator' is abstract; cannot be instantiated
    is it a problem of API version, SK, NDK or the library ? thanks for your help

    • @WittCode
      @WittCode  3 роки тому +1

      Hey there! Did you import the right Session class? Go to the top of the page at your imports and make sure it is the javax.mail.Session and not another one!

    •  3 роки тому

      @@WittCode thanks..sorry

    •  3 роки тому

      at the end when i Run it "Process finished with exit code 1"
      so i got a lot log
      ..
      Exception in thread "main" javax.mail.MessagingException: IOException while sending message;
      nested exception is:
      java.io.IOException: No MimeBodyPart content
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1365)
      at javax.mail.Transport.send0(Transport.java:255)
      at javax.mail.Transport.send(Transport.java:124)
      at fr.jeredez.myapplication.MyEmail.main(MyEmail.java:56)
      Caused by: java.io.IOException: No MimeBodyPart content
      at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:116)
      at javax.activation.DataHandler.writeTo(DataHandler.java:305)
      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694)
      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:996)
      at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:561)
      at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:84)
      at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
      at javax.activation.DataHandler.writeTo(DataHandler.java:317)
      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694)
      at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1913)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1315)
      ... 3 more
      Caused by: javax.mail.MessagingException: No MimeBodyPart content
      at javax.mail.internet.MimeBodyPart.getContentStream(MimeBodyPart.java:618)
      at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:100)
      ... 13 more

    • @WittCode
      @WittCode  3 роки тому +1

      @ Of the errors you sent me usually the one that is important is the one that contains info about your java file which seems to be called MyEmail.java? The error is thrown on line 56 and it is because you have no content in the email you are trying to send!

    •  3 роки тому

      @@WittCode okay i'm so dumb ; i typed attachment.setContent instead of messageBodyPart.setContent ...

  • @nelsonantonio5870
    @nelsonantonio5870 3 роки тому

    Hello Sir, works in JAVA Android ? Great video.

    • @WittCode
      @WittCode  3 роки тому

      Hey Nelson! I am not 100% sure but if you use the same Java libraries I don't see why it wouldn't work! There might just be some extra permissions or something you need to work with. 😃

  • @vijaybharat4089
    @vijaybharat4089 2 роки тому

    Good

  • @Obaba-ey3gy
    @Obaba-ey3gy 2 роки тому

    how to attach selected files without mentioning in file

  • @theexploreaustralia
    @theexploreaustralia 3 роки тому

    brother can you give its source code

    • @WittCode
      @WittCode  3 роки тому +1

      Hey Ali! I will be posting the source code to a lot of videos when I get my personal computer working again haha I'm using my work computer and I don't want to mess with the git settings!

    • @theexploreaustralia
      @theexploreaustralia 3 роки тому

      I got solution now 😅 after whole day writing your code

    • @theexploreaustralia
      @theexploreaustralia 3 роки тому

      Can I get your WhatsApp number if you don't mind

    • @WittCode
      @WittCode  3 роки тому

      @@theexploreaustralia haha sorry about that man 😀

  • @deepakkumars8139
    @deepakkumars8139 3 роки тому

    javax.mail.MessagingException: Exception reading response;
    nested exception is:
    javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    How to solve this?

    • @WittCode
      @WittCode  3 роки тому

      Hey Deepak! This must be something to do with setting up the session in the video. For the properties object did you specify the protocol to be smtp? I believe it is properties.put("mail.transport.protocol", "smtp");

    • @deepakkumars8139
      @deepakkumars8139 3 роки тому

      @@WittCode yes I did everything what you said in your video

    • @m3jh
      @m3jh 2 роки тому

      it could be that your antivirus is blocking you

  • @jonathanm.6001
    @jonathanm.6001 3 роки тому

    Very helpful! However, I am still getting the following issue. Looks like I need JavaBean Activation, but I can’t figure out how to download it. How do I fix this:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
    at SendEmail.main(SendEmail.java:24)
    Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 1 more

    • @WittCode
      @WittCode  3 роки тому

      Hey Jonathan! This seems like an issue loading the Java mail api. Are you using maven and IntelliJ or just IntelliJ?

    • @jonathanm.6001
      @jonathanm.6001 3 роки тому

      @@WittCode Oh, I got it figured it out. Thank you so much for the quick response!

    • @adamadamadde
      @adamadamadde 2 роки тому

      @@WittCode hey i get the same error and I'm using intelliJUltimate, do u know how I can fix this ? :))) //longtime subscriber

  • @joaquingutierrez5435
    @joaquingutierrez5435 3 роки тому

    how can i add signature and closing to mail?