How to send a mail using java code in eclipse
What you will learn here about java Email send
- How to send a mail using java code in eclipse
- java send email with attachment
How to send a mail using java code in eclipse
Please follow the following steps to know how to send a mail using java code in eclipse
1)Please first sign in first your Gmail or Email account in the browser.
2)Now please click on the following link to enable security option so that you can send email using python
Gmail allows the app to send email
3)Now please click on the following link to enable the captcha option so that you can send an email using python without login the browser.
Gmail unlock captcha to send email
4)Please download the following code to send Email using java
Java email send code (570 downloads)
5)Now please unzip the downloaded code
6)Open unzip code with your Eclipse IDE
7)Now please open CreateEmail.java file and modify the receiver Email address which is shown below and save the changes
8)Now please open the SendEmail.java file and modify sender email name and password which is shown below and save the changes
9)Now please run the Email.java file to send Email which is shown below
10)Now please check your receiver email to see a sent email which is shown below
java send email with attachment
Please follow the following steps to know how to send Email with attachment in java
emailMessage.setSubject("Test Email"); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Please Find the attached file"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); String filename = "C:\\Users\\ABCD\\Desktop\\pic.png"; DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName("pic.png"); multipart.addBodyPart(messageBodyPart); emailMessage.setContent(multipart);
In the downloaded code please modify the following things:
- Please comment two lines of CreateEmail.java file which is shown below
- Please add above code in CreateEmail.java file which is shown below
- Modify the path of file with respect to your system which is shown below