Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
J
java-demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leon Li
java-demo
Commits
9c31f4e9
Commit
9c31f4e9
authored
Apr 27, 2020
by
l2m2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upload.
parent
522bb086
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
0 deletions
+71
-0
.gitignore
.gitignore
+1
-0
HelloWorld.java
HelloWorld.java
+5
-0
README.md
README.md
+6
-0
SendMailDemo.java
SendMailDemo.java
+59
-0
javax.mail.jar
javax.mail.jar
+0
-0
No files found.
.gitignore
0 → 100644
View file @
9c31f4e9
*.class
\ No newline at end of file
HelloWorld.java
0 → 100644
View file @
9c31f4e9
public
class
HelloWorld
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello World"
);
}
}
\ No newline at end of file
README.md
View file @
9c31f4e9
# java-demo
邮件测试
```
java
$
javac
-
cp
"javax.mail.jar;"
SendMail
.
java
$
java
-
cp
"javax.mail.jar;"
SendMail
```
\ No newline at end of file
SendMailDemo.java
0 → 100644
View file @
9c31f4e9
import
javax.mail.*
;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeMessage
;
import
java.util.Date
;
import
java.util.Properties
;
public
class
SendMailDemo
{
private
static
final
String
USERNAME
=
"leon.li@topibd.com"
;
private
static
final
String
PASSWORD
=
"xxx"
;
public
static
void
main
(
String
[]
args
)
{
String
mailFrom
=
"leon.li@topibd.com"
;
String
mailTo
=
"114723704@qq.com"
;
String
mailSubject
=
"Send Email Demo"
;
String
mailText
=
"Send Email Demo Body"
;
SendMailDemo
m
=
new
SendMailDemo
();
try
{
m
.
sendMail
(
mailFrom
,
mailTo
,
mailSubject
,
mailText
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
private
void
sendMail
(
String
mailFrom
,
String
mailTo
,
String
mailSubject
,
String
mailText
)
throws
Exception
{
Properties
config
=
createConfiguration
();
Session
session
=
Session
.
getInstance
(
config
,
new
Authenticator
()
{
@Override
protected
PasswordAuthentication
getPasswordAuthentication
()
{
return
new
PasswordAuthentication
(
SendMailDemo
.
USERNAME
,
SendMailDemo
.
PASSWORD
);
}
});
// Creates email message
Message
message
=
new
MimeMessage
(
session
);
message
.
setSentDate
(
new
Date
());
message
.
setFrom
(
new
InternetAddress
(
mailFrom
));
message
.
setRecipient
(
Message
.
RecipientType
.
TO
,
new
InternetAddress
(
mailTo
));
message
.
setSubject
(
mailSubject
);
message
.
setText
(
mailText
);
// Send a message
Transport
.
send
(
message
,
SendMailDemo
.
USERNAME
,
SendMailDemo
.
PASSWORD
);
}
private
Properties
createConfiguration
()
{
return
new
Properties
()
{
{
put
(
"mail.smtp.auth"
,
"true"
);
put
(
"mail.smtp.host"
,
"smtp.exmail.qq.com"
);
put
(
"mail.smtp.port"
,
"25"
);
// put("mail.smtp.starttls.enable", "false");
}
};
}
}
\ No newline at end of file
javax.mail.jar
0 → 100644
View file @
9c31f4e9
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment