forked from chhrrr/RAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,14 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.mail.internet.AddressException; | ||
|
||
import com.google.gson.Gson; | ||
import com.taobao.rigel.rap.account.bo.User; | ||
import com.taobao.rigel.rap.common.ActionBase; | ||
import com.taobao.rigel.rap.common.ContextManager; | ||
import com.taobao.rigel.rap.common.Logger; | ||
import com.taobao.rigel.rap.common.MailUtils; | ||
|
||
/** | ||
* account action | ||
|
@@ -30,6 +33,19 @@ public class AccountAction extends ActionBase { | |
private String SSO_TOKEN; | ||
private String BACK_URL; | ||
|
||
public String test() throws AddressException, InterruptedException { | ||
String[] list = new String[2]; | ||
int i = 1; | ||
list[0] = "[email protected]"; | ||
list[1] = "[email protected]"; | ||
for (; i < 2; i++) { | ||
MailUtils.sendMessage(list, "RAP通知消息" + (i++), | ||
"this is an informing message!中文测试 hahahahaha"); | ||
Thread.sleep(500); | ||
} | ||
return SUCCESS; | ||
} | ||
|
||
public String getSSO_TOKEN() { | ||
return SSO_TOKEN; | ||
} | ||
|
@@ -227,7 +243,7 @@ public String doChangeProfile() { | |
public String sendBucSSOToken() { | ||
return SUCCESS; | ||
} | ||
|
||
public String logData() { | ||
Map<String, Object> obj = new HashMap<String, Object>(); | ||
obj.put("online", this.getCountOfOnlineUserList()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.taobao.rigel.rap.common; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.mail.Address; | ||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
import javax.mail.PasswordAuthentication; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.AddressException; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
public class MailUtils { | ||
public static void sendMessage(String[] addressList, String title, | ||
String content) throws AddressException { | ||
Address[] addresses = new Address[addressList.length]; | ||
for (int i = 0; i < addressList.length; i++) { | ||
addresses[i] = new InternetAddress(addressList[i]); | ||
} | ||
|
||
// Sender's email ID needs to be mentioned | ||
String from = "[email protected]"; | ||
final String username = ""; | ||
final String password = ""; | ||
|
||
// Get system properties | ||
Properties props = System.getProperties(); | ||
|
||
// Setup mail server | ||
props.put("mail.smtp.host", "smtp-inc.alibaba-inc.com"); | ||
props.put("mail.smtp.port", "25"); | ||
props.put("mail.smtp.auth", "true"); | ||
|
||
props.put("mail.smtp.starttls.enable", "true"); | ||
|
||
// Get the default Session object. | ||
Session session = Session.getDefaultInstance(props, | ||
new javax.mail.Authenticator() { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication( | ||
username, password); | ||
} | ||
}); | ||
|
||
try { | ||
// Create a default MimeMessage object. | ||
MimeMessage message = new MimeMessage(session); | ||
|
||
// Set From: header field of the header. | ||
message.setFrom(new InternetAddress(from)); | ||
|
||
// Set To: header field of the header. | ||
message.addRecipients(Message.RecipientType.BCC, addresses); | ||
|
||
// Set Subject: header field | ||
message.setSubject(title, "UTF-8"); | ||
|
||
// Now set the actual message | ||
message.setText(content, "UTF-8"); | ||
|
||
// Send message | ||
Transport.send(message); | ||
System.out.println("Sent message successfully...."); | ||
} catch (MessagingException mex) { | ||
mex.printStackTrace(); | ||
} | ||
} | ||
} |