package mail;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class SendFlexMail {
private static final String SMTP_HOST_NAME = "smtp.163.com";
private static final String SMTP_AUTH_USER = "feixianyuexin";
private static final String SMTP_AUTH_PWD = "fuckyourpassword";
// Add List of Email address to who email needs to be sent to
private String[] emailList;
public String sendFlexMail(String flexMail){
String result="";
JSONArray flexJavaMail = JSONArray.fromObject(flexMail);
emailList = new String[2];
JSONObject mailJsonObj = JSONObject.fromObject(flexJavaMail.getString(0));
emailList[0] = mailJsonObj.getString("senderEmail");//send mail to yourself
emailList[1] = mailJsonObj.getString("sendToEmail");
String senderName = mailJsonObj.getString("senderName");
String sendToName = mailJsonObj.getString("sendToName");
String senderMail = mailJsonObj.getString("senderEmail");
String emailMessage = mailJsonObj.getString("emailMessage");
String emailTopic = sendToName+":A Letter From Your Friend "+senderName;
try{
postMail(emailList,emailTopic, emailMessage,senderMail);
result="Congratulations!";
}catch (MessagingException e){
e.printStackTrace();
}
return result;
}
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本文主要介绍和实现怎么使用Flex-java来实现Email的发送。这尤其是在做用户回馈的时候需要用到。当然这实现的只要是一个简单的例子。正在执行发送Email功能还是使用java来实现的,Flex只不过提供了数据的输入和封装。使用的原理很简单:<br>Flex-Form <--接受用户输入<br> ||<br> ||使用RemoteObject方式就用户输入的数据封装成json格式传递到后台java bean<br> ||<br>Java Bean()--->执行真正的Email发送----->回馈消息---->Flex-Form
资源推荐
资源详情
资源评论
收起资源包目录
FlexMail.rar (34个子文件)
FlexMail
.project 1KB
flex_libs
.settings
org.eclipse.core.resources.prefs 88B
org.eclipse.wst.common.component 586B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.common.project.facet.core.xml 269B
org.eclipse.jst.common.project.facet.core.prefs 357B
.actionScriptProperties 1KB
html-template
AC_OETags.js 8KB
index.template.html 4KB
history
history.js 24KB
historyFrame.html 807B
history.css 371B
playerProductInstall.swf 657B
src
mail
SendFlexMail.java 3KB
WebContent
WEB-INF
flex
messaging-config.xml 513B
remoting-config.xml 519B
services-config.xml 4KB
proxy-config.xml 826B
web.xml 2KB
src
lib
classes
mail
SendFlexMail.class 4KB
SendFlexMail$SMTPAuthenticator.class 931B
META-INF
MANIFEST.MF 252B
bin-debug
AC_OETags.js 8KB
history
history.js 24KB
historyFrame.html 807B
history.css 371B
playerProductInstall.swf 657B
mailFormCSS.css 410B
FlexMail.swf 400KB
FlexMail.html 4KB
.classpath 624B
flex_src
mailFormCSS.css 410B
FlexMail.mxml 4KB
.flexProperties 360B
共 34 条
- 1
黑夜愁客
- 粉丝: 81
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页