Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9cf8a5d

Browse files
SENDING email
1 parent 2a21a1f commit 9cf8a5d

File tree

8 files changed

+161
-57
lines changed

8 files changed

+161
-57
lines changed

‎.idea/workspace.xml

Lines changed: 76 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Java_revise.iml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,25 @@
1616
<SOURCES />
1717
</library>
1818
</orderEntry>
19+
<orderEntry type="module-library">
20+
<library>
21+
<CLASSES>
22+
<root url="jar://$MODULE_DIR$/added_library/javax.mail-1.6.1.jar!/" />
23+
</CLASSES>
24+
<JAVADOC />
25+
<SOURCES />
26+
</library>
27+
</orderEntry>
28+
<orderEntry type="module-library">
29+
<library>
30+
<CLASSES />
31+
<JAVADOC>
32+
<root url="jar://$MODULE_DIR$/added_library/jaf-1_1_1.zip!/jaf-1.1.1/docs/javadocs" />
33+
</JAVADOC>
34+
<SOURCES>
35+
<root url="jar://$MODULE_DIR$/added_library/jaf-1_1_1.zip!/jaf-1.1.1/demo" />
36+
</SOURCES>
37+
</library>
38+
</orderEntry>
1939
</component>
2040
</module>

‎added_library/jaf-1_1_1.zip

371 KB
Binary file not shown.

‎added_library/javax.mail-1.6.1.jar

639 KB
Binary file not shown.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.example.hello_world_package;
2+
3+
4+
import java.net.UnknownHostException;
5+
import java.util.*;
6+
import javax.mail.*;
7+
import javax.mail.internet.*;
8+
9+
10+
public class Network_Programming_Sending_Email {
11+
12+
public static void main(String [] args) throws UnknownHostException, NoSuchProviderException {
13+
14+
//FOR THIS CODE TO WORK, you must first allow your mail-sending gmail id to be accessible by less secure apps in the settings
15+
16+
//ALSO ADD JavaMail API jar to your library first
17+
18+
Properties properties = System.getProperties();
19+
properties.put("mail.smtp.auth", "true");
20+
properties.put("mail.smtp.starttls.enable", "true");
21+
properties.put("mail.smtp.port", "587");
22+
properties.put("mail.smtp.starttls.enable", "true");
23+
24+
// Get the default Session object
25+
Session session = Session.getDefaultInstance(properties,null);
26+
27+
28+
29+
try {
30+
// Create a default MimeMessage object.
31+
MimeMessage message = new MimeMessage(session);
32+
33+
// Set Subject: header field
34+
message.setSubject("This is mail subject field.");
35+
36+
// Now set the actual message
37+
message.setText("This is the actual message sent in the mail.");
38+
39+
message.addRecipients(Message.RecipientType.TO, "aashish73134@gmail.com");
40+
41+
// Send message
42+
43+
String emailHost = "smtp.gmail.com";
44+
String fromUser = "auggieeeeeeeee";//just the id alone without @gmail.com
45+
String fromUserEmailPassword = "YOUR_gmail_PASSWORD_HERE";
46+
47+
Transport transport = session.getTransport("smtp");
48+
49+
transport.connect(emailHost, fromUser, fromUserEmailPassword);
50+
transport.sendMessage(message, message.getAllRecipients());
51+
transport.close();
52+
System.out.println("Email sent successfully.");
53+
54+
System.out.println("Message successfully sent....");
55+
} catch (MessagingException m) {
56+
57+
m.printStackTrace();
58+
System.out.println("Could not send mail.");
59+
}
60+
61+
62+
63+
64+
}
65+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /