├── .classpath
├── .github
└── FUNDING.yml
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── LICENSE
├── README.md
├── pom.xml
├── src
├── main
│ └── java
│ │ └── com
│ │ └── ashish
│ │ └── Email_Sender_Using_Java
│ │ └── App.java
└── test
│ └── java
│ └── com
│ └── ashish
│ └── Email_Sender_Using_Java
│ └── AppTest.java
└── target
├── classes
└── com
│ └── ashish
│ └── Email_Sender_Using_Java
│ ├── App$1.class
│ └── App.class
└── test-classes
└── com
└── ashish
└── Email_Sender_Using_Java
└── AppTest.class
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ["https://paypal.me/ashish2030",
13 | "https://www.buymeacoffee.com/ashish2030"]
14 | # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
15 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Email-Sender-Using-Java
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3 | org.eclipse.jdt.core.compiler.compliance=1.5
4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7 | org.eclipse.jdt.core.compiler.release=disabled
8 | org.eclipse.jdt.core.compiler.source=1.5
9 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Ashish Kumar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Email_Sender_With_attachment_using_Java
2 |
3 | https://user-images.githubusercontent.com/61516051/118388638-503a6380-b643-11eb-926c-f20f3556dccd.mp4
4 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.ashish
6 | Email-Sender-Using-Java
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | Email-Sender-Using-Java
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.sun.mail
20 | javax.mail
21 | 1.6.2
22 |
23 |
24 | junit
25 | junit
26 | 3.8.1
27 | test
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/main/java/com/ashish/Email_Sender_Using_Java/App.java:
--------------------------------------------------------------------------------
1 | package com.ashish.Email_Sender_Using_Java;
2 | import java.io.File;
3 | import java.util.*;
4 | import javax.mail.Authenticator;
5 | import javax.mail.Message;
6 | import javax.mail.PasswordAuthentication;
7 | import javax.mail.Session;
8 | import javax.mail.Transport;
9 | import javax.mail.internet.InternetAddress;
10 | import javax.mail.internet.MimeBodyPart;
11 | import javax.mail.internet.MimeMessage;
12 | import javax.mail.internet.MimeMultipart;
13 |
14 | public class App
15 | {
16 |
17 | public static void main( String[] args )
18 | {
19 | System.out.println("preparing to send message ...");
20 | String message = "Happy Coding ";
21 | String subject = "Checking my Code";
22 | String to = "rs8657511@gmail.com";
23 | String from = "Kumarashish79924@gmail.com";
24 |
25 | sendAttachment(message,subject,to,from);
26 | }
27 | private static void sendAttachment(String message, String subject, String to, String from) {
28 |
29 | //Variable for gmail
30 | String host="smtp.gmail.com";
31 |
32 | //get the system properties
33 | Properties properties = System.getProperties();
34 | System.out.println("PROPERTIES "+properties);
35 |
36 | //setting important information to properties object
37 |
38 | //host set
39 | properties.put("mail.smtp.host", host);
40 | properties.put("mail.smtp.port","465");
41 | properties.put("mail.smtp.ssl.enable","true");
42 | properties.put("mail.smtp.auth","true");
43 |
44 | //Step 1: to get the session object..
45 | Session session=Session.getInstance(properties, new Authenticator() {
46 | @Override
47 | protected PasswordAuthentication getPasswordAuthentication() {
48 | return new PasswordAuthentication("kumarashish79924@gmail.com", "Chitkara@123");
49 | }
50 | });
51 |
52 | session.setDebug(true);
53 |
54 | //Step 2 : compose the message [text,multi media]
55 |
56 | MimeMessage m = new MimeMessage(session);
57 | try {
58 |
59 | //from email
60 | m.setFrom(from);
61 |
62 | //adding recipient to message
63 | m.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
64 |
65 | //adding subject to message
66 | m.setSubject(subject);
67 |
68 |
69 | //attach
70 |
71 | //file path
72 | String path="C:\\Users\\Ashish\\Desktop\\image\\hacker.jpg";
73 |
74 |
75 | MimeMultipart mimeMultipart = new MimeMultipart();
76 | MimeBodyPart textMime = new MimeBodyPart();//text
77 | MimeBodyPart fileMime = new MimeBodyPart();//file
78 |
79 | try {
80 |
81 | textMime.setText(message); //add text in it
82 |
83 | File file=new File(path);
84 | fileMime.attachFile(file); //add file path in it
85 |
86 | mimeMultipart.addBodyPart(textMime); //add both in its parent
87 | mimeMultipart.addBodyPart(fileMime); //add both in its parent
88 |
89 |
90 | } catch (Exception e) {
91 |
92 | e.printStackTrace();
93 | }
94 |
95 |
96 | m.setContent(mimeMultipart);
97 |
98 |
99 | //send
100 |
101 | //Step 3 : send the message using Transport class
102 | Transport.send(m);
103 |
104 |
105 |
106 | }catch (Exception e) {
107 | e.printStackTrace();
108 | }
109 |
110 | System.out.println("Sent success...................");
111 |
112 |
113 |
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/test/java/com/ashish/Email_Sender_Using_Java/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.ashish.Email_Sender_Using_Java;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/target/classes/com/ashish/Email_Sender_Using_Java/App$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ashish2030/Email_Sender_With_attachment_using_Java/37e0f078b8447391e332a9889a7e52aa3700acd6/target/classes/com/ashish/Email_Sender_Using_Java/App$1.class
--------------------------------------------------------------------------------
/target/classes/com/ashish/Email_Sender_Using_Java/App.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ashish2030/Email_Sender_With_attachment_using_Java/37e0f078b8447391e332a9889a7e52aa3700acd6/target/classes/com/ashish/Email_Sender_Using_Java/App.class
--------------------------------------------------------------------------------
/target/test-classes/com/ashish/Email_Sender_Using_Java/AppTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ashish2030/Email_Sender_With_attachment_using_Java/37e0f078b8447391e332a9889a7e52aa3700acd6/target/test-classes/com/ashish/Email_Sender_Using_Java/AppTest.class
--------------------------------------------------------------------------------