Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosn committed May 7, 2014
1 parent b52de39 commit 98c6fde
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 5 deletions.
Binary file added WebContent/WEB-INF/lib/javax.mail.jar
Binary file not shown.
Binary file removed WebContent/WEB-INF/lib/mail.jar
Binary file not shown.
18 changes: 17 additions & 1 deletion src/com/taobao/rigel/rap/account/web/action/AccountAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 7 additions & 4 deletions src/com/taobao/rigel/rap/account/web/action/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="account" extends="rap-default" namespace="/account">
<action name="test"
class="com.taobao.rigel.rap.account.web.action.AccountAction" method="test">
<result name="success" type="velocity">/bcom/json.cb.vm</result>
</action>
<action name="login"
class="com.taobao.rigel.rap.account.web.action.AccountAction" method="login">
<result name="success" type="velocity">/account/login.vm</result>
Expand All @@ -24,10 +28,9 @@
class="com.taobao.rigel.rap.account.web.action.AccountAction" method="doLogout">
<result name="success" type="velocity">/platform/home.vm</result>
</action>
<!-- <action name="register"
class="com.taobao.rigel.rap.account.web.action.AccountAction" method="register">
<result name="success" type="velocity">/account/register.vm</result>
</action> -->
<!-- <action name="register" class="com.taobao.rigel.rap.account.web.action.AccountAction"
method="register"> <result name="success" type="velocity">/account/register.vm</result>
</action> -->
<action name="doRegister"
class="com.taobao.rigel.rap.account.web.action.AccountAction" method="doRegister">
<result name="success" type="velocity">/platform/home.vm</result>
Expand Down
70 changes: 70 additions & 0 deletions src/com/taobao/rigel/rap/common/MailUtils.java
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();
}
}
}

0 comments on commit 98c6fde

Please sign in to comment.