Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
saasio
Project
Overview
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
reyun
saasio
Commits
cc658f18
Commit
cc658f18
authored
Apr 02, 2018
by
carrieyzzhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sendcloud
parent
0839344c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletion
+79
-1
EmailThread.java
src/main/java/com/reyun/task/EmailThread.java
+12
-1
SendCommonPostMail.java
src/main/java/com/reyun/util/SendCommonPostMail.java
+67
-0
No files found.
src/main/java/com/reyun/task/EmailThread.java
View file @
cc658f18
package
com
.
reyun
.
task
;
package
com
.
reyun
.
task
;
import
com.reyun.util.MailUtils
;
import
com.reyun.util.MailUtils
;
import
com.reyun.util.SendCommonPostMail
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
import
java.util.List
;
...
@@ -11,6 +14,8 @@ import java.util.List;
...
@@ -11,6 +14,8 @@ import java.util.List;
public
class
EmailThread
public
class
EmailThread
extends
Thread
{
extends
Thread
{
protected
Logger
logger
=
LoggerFactory
.
getLogger
(
EmailThread
.
class
);
private
String
title
;
private
String
title
;
private
String
content
;
private
String
content
;
private
List
<
String
>
receiver
;
private
List
<
String
>
receiver
;
...
@@ -31,7 +36,13 @@ public class EmailThread
...
@@ -31,7 +36,13 @@ public class EmailThread
try
{
try
{
MailUtils
.
sendHtmlEmail
(
title
,
content
,
receiver
);
MailUtils
.
sendHtmlEmail
(
title
,
content
,
receiver
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"fail to send email by reyun.com."
+
e
.
getMessage
());
}
try
{
SendCommonPostMail
.
sendMail
(
title
,
content
,
"zhangxiaoyan@reyun.com"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to send email 2 zhangxiaoyan by sendcloud.......title is "
+
title
);
}
}
}
}
...
...
src/main/java/com/reyun/util/SendCommonPostMail.java
0 → 100644
View file @
cc658f18
package
com
.
reyun
.
util
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
SendCommonPostMail
{
protected
static
Logger
logger
=
LoggerFactory
.
getLogger
(
SendCommonPostMail
.
class
);
static
String
url
=
"http://api.sendcloud.net/apiv2/mail/send"
;
static
String
apiUser
=
"service24h"
;
static
String
apiKey
=
"v5WhuknT9zp4xWIz"
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
emial
=
"carrie_yz@163.com"
;
String
subject
=
"test"
;
String
content
=
"test"
;
SendCommonPostMail
.
sendMail
(
emial
,
subject
,
content
);
}
public
static
boolean
sendMail
(
String
toEmail
,
String
subject
,
String
content
)
{
HttpClient
httpclient
=
new
DefaultHttpClient
();
HttpPost
httPost
=
new
HttpPost
(
url
);
List
params
=
new
ArrayList
();
// 您需要登录SendCloud创建API_USER,使用API_USER和API_KEY才可以进行邮件的发送。
params
.
add
(
new
BasicNameValuePair
(
"apiUser"
,
apiUser
));
params
.
add
(
new
BasicNameValuePair
(
"apiKey"
,
apiKey
));
params
.
add
(
new
BasicNameValuePair
(
"from"
,
"service@sendcloud.im"
));
params
.
add
(
new
BasicNameValuePair
(
"fromName"
,
"reyun"
));
params
.
add
(
new
BasicNameValuePair
(
"to"
,
toEmail
));
params
.
add
(
new
BasicNameValuePair
(
"subject"
,
subject
));
params
.
add
(
new
BasicNameValuePair
(
"html"
,
content
));
boolean
success
=
false
;
try
{
httPost
.
setEntity
(
new
UrlEncodedFormEntity
(
params
,
"UTF-8"
));
// 请求
HttpResponse
response
=
httpclient
.
execute
(
httPost
);
// 处理响应
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
// 正常返回
// 读取xml文档
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
success
=
true
;
}
else
{
logger
.
error
(
"sendcloud response status is error......."
);
}
httPost
.
releaseConnection
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"fail to send mail to "
+
toEmail
);
}
return
success
;
}
}
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