Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
common
Commits
c7900db5
Commit
c7900db5
authored
Mar 04, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://key@gitlab.egolm.com/key/common.git
parents
9659c747
eb909335
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
2 deletions
+63
-2
MailUtil.java
src/main/java/com/egolm/common/MailUtil.java
+63
-2
No files found.
src/main/java/com/egolm/common/MailUtil.java
View file @
c7900db5
...
@@ -78,6 +78,62 @@ public class MailUtil {
...
@@ -78,6 +78,62 @@ public class MailUtil {
}
}
public
static
void
sendBySmtps
(
String
host
,
Integer
port
,
final
String
username
,
final
String
password
,
final
String
from
,
String
subject
,
String
content
,
File
[]
attachments
,
String
...
emailTo
)
{
public
static
void
sendBySmtps
(
String
host
,
Integer
port
,
final
String
username
,
final
String
password
,
final
String
from
,
String
subject
,
String
content
,
File
[]
attachments
,
String
...
emailTo
)
{
sendBySmtps
(
host
,
port
,
username
,
password
,
from
,
null
,
subject
,
content
,
attachments
,
emailTo
);
/*boolean is_auth = StringUtil.isNotBlank(username) && StringUtil.isNotBlank(password);
Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "smtps");
properties.setProperty("mail.smtp.auth", is_auth ? "true" : "false");
properties.setProperty("mail.smtp.host", String.valueOf(host));
properties.setProperty("mail.smtp.port", String.valueOf(port));
properties.setProperty("mail.smtp.socketFactory.port", String.valueOf(port));
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
try {
Session session = is_auth ? Session.getDefaultInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
}) : Session.getDefaultInstance(properties);
Message message = new MimeMessage(session);
Address fromAddress = new InternetAddress(from, "上海国际电影节报名 SIFF PROJECT SUBMISSION", "UTF-8");
message.setFrom(fromAddress);
List<Address> addresses = new ArrayList<Address>();
for(String email : emailTo) {
addresses.add(new InternetAddress(email));
}
message.setRecipients(Message.RecipientType.TO, addresses.toArray(new Address[addresses.size()]));
message.setSubject(subject);
message.setSentDate(new Date());
Multipart m = new MimeMultipart();
BodyPart bp = new MimeBodyPart();
bp.setContent(content, "text/html; charset=gb2312");
m.addBodyPart(bp);
message.setContent(m);
if(attachments != null) {
for(File file : attachments) {
MimeBodyPart mbpFile = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(file);
mbpFile.setDataHandler(new DataHandler(fileDataSource));
String filename = fileDataSource.getName();
String name = filename.substring(0, filename.lastIndexOf("."));
String exname = filename.substring(filename.lastIndexOf("."));
String encodeName = MimeUtility.encodeText(name) + exname;
mbpFile.setFileName(encodeName);
m.addBodyPart(mbpFile);
}
}
Transport.send(message);
} catch (Exception e) {
throw new PluginException(e);
}*/
}
public
static
void
sendBySmtps
(
String
host
,
Integer
port
,
final
String
username
,
final
String
password
,
final
String
from
,
final
String
fromName
,
String
subject
,
String
content
,
File
[]
attachments
,
String
...
emailTo
)
{
System
.
out
.
println
(
fromName
);
boolean
is_auth
=
StringUtil
.
isNotBlank
(
username
)
&&
StringUtil
.
isNotBlank
(
password
);
boolean
is_auth
=
StringUtil
.
isNotBlank
(
username
)
&&
StringUtil
.
isNotBlank
(
password
);
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"mail.transport.protocol"
,
"smtps"
);
properties
.
setProperty
(
"mail.transport.protocol"
,
"smtps"
);
...
@@ -94,7 +150,12 @@ public class MailUtil {
...
@@ -94,7 +150,12 @@ public class MailUtil {
}
}
})
:
Session
.
getDefaultInstance
(
properties
);
})
:
Session
.
getDefaultInstance
(
properties
);
Message
message
=
new
MimeMessage
(
session
);
Message
message
=
new
MimeMessage
(
session
);
Address
fromAddress
=
new
InternetAddress
(
from
);
Address
fromAddress
;
if
(
fromName
!=
null
)
{
fromAddress
=
new
InternetAddress
(
from
,
fromName
,
"UTF-8"
);
}
else
{
fromAddress
=
new
InternetAddress
(
from
);
}
message
.
setFrom
(
fromAddress
);
message
.
setFrom
(
fromAddress
);
List
<
Address
>
addresses
=
new
ArrayList
<
Address
>();
List
<
Address
>
addresses
=
new
ArrayList
<
Address
>();
for
(
String
email
:
emailTo
)
{
for
(
String
email
:
emailTo
)
{
...
@@ -132,6 +193,6 @@ public class MailUtil {
...
@@ -132,6 +193,6 @@ public class MailUtil {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
MailUtil
.
sendBySmtps
(
"smtphz.qiye.163.com"
,
994
,
"filmpassword@siff.com"
,
"siffstvf2018"
,
"filmpassword@siff.com"
,
"测试"
,
"测试"
,
null
,
"747539993@qq
.com"
);
MailUtil
.
sendBySmtps
(
"smtphz.qiye.163.com"
,
994
,
"filmpassword@siff.com"
,
"siffstvf2018"
,
"filmpassword@siff.com"
,
"上海国际电影节"
,
"测试"
,
"测试"
,
null
,
"13384825689@163
.com"
);
}
}
}
}
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