Revision: 4054
Author: seba.wagner
Date: Sun Aug 14 09:31:35 2011
Log: Fixes: Thread and Taskexecutor for Mail Sending
http://code.google.com/p/openmeetings/source/detail?r=4054
Modified:
/branches/dev/injection/server/red5/webapps/openmeetings/WEB-INF/red5-applicationContext.xml
/branches/dev/injection/src/app/org/openmeetings/app/data/conference/Invitationmanagement.java
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailHandler.java
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailThread.java
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailiCalThread.java
/branches/dev/injection/src/app/org/openmeetings/utils/mail/SmtpAuthenticator.java
=======================================
---
/branches/dev/injection/server/red5/webapps/openmeetings/WEB-INF/red5-applicationContext.xml
Sun Aug 14 07:43:11 2011
+++
/branches/dev/injection/server/red5/webapps/openmeetings/WEB-INF/red5-applicationContext.xml
Sun Aug 14 09:31:35 2011
@@ -181,8 +181,25 @@
<!-- Templates -->
<bean id="registerUserTemplate"
class="org.openmeetings.app.templates.RegisterUserTemplate" />
+ <!-- Thread Executor -->
+ <bean id="mailTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
+ <property name="corePoolSize" value="5" />
+ <property name="maxPoolSize" value="10" />
+ <property name="queueCapacity" value="25" />
+ </bean>
+
+ <bean id="mailThread" class="org.openmeetings.utils.mail.MailThread">
+ <constructor-arg ref="mailTaskExecutor" />
+ </bean>
+
+ <bean id="mailiCalThread"
class="org.openmeetings.utils.mail.MailiCalThread">
+ <constructor-arg ref="mailTaskExecutor" />
+ </bean>
+
+
<tx:annotation-driven transaction-manager="jpaTransactionManager"/>
+
<context:annotation-config/>
</beans>
=======================================
---
/branches/dev/injection/src/app/org/openmeetings/app/data/conference/Invitationmanagement.java
Sun Aug 14 04:56:25 2011
+++
/branches/dev/injection/src/app/org/openmeetings/app/data/conference/Invitationmanagement.java
Sun Aug 14 09:31:35 2011
@@ -1,6 +1,5 @@
package org.openmeetings.app.data.conference;
-import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -34,6 +33,7 @@
import org.openmeetings.utils.crypt.ManageCryptStyle;
import org.openmeetings.utils.mail.IcalHandler;
import org.openmeetings.utils.mail.MailHandler;
+import org.openmeetings.utils.mail.MailiCalThread;
import org.openmeetings.utils.math.CalendarPatterns;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
@@ -71,8 +71,8 @@
private UsersDaoImpl usersDao;
@Autowired
private MailHandler mailHandler;
-
- private final SimpleDateFormat dateFormat = new
SimpleDateFormat("HH:mm");
+ @Autowired
+ private MailiCalThread mailiCalThread;
/**
* Sending invitation within plain mail
@@ -678,7 +678,9 @@
// Defining Organizer
Users user = userManagement.getUserById(organizer_userId);
- OmTimeZone omTimeZone =
omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
+ // TODO: Check time zone handling in iCal Mail
+ // OmTimeZone omTimeZone =
+ // omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
IcalHandler handler = new
IcalHandler(IcalHandler.ICAL_METHOD_CANCEL);
@@ -702,14 +704,13 @@
GregorianCalendar end = new GregorianCalendar();
end.setTime(enddate);
- String meetingId = handler.addNewMeeting(start, end,
- point.getAppointmentName(), atts, subject,
attendeeList,
- point.getIcalId(), jNameTimeZone);
+ handler.addNewMeeting(start, end, point.getAppointmentName(),
atts,
+ subject, attendeeList, point.getIcalId(),
jNameTimeZone);
log.debug(handler.getICalDataAsString());
- MailHandler.sendIcalMessage(email, subject,
- handler.getIcalAsByteArray(), message);
+ mailiCalThread.doSend(email, subject,
handler.getIcalAsByteArray(),
+ message);
return null;
}
@@ -756,14 +757,13 @@
GregorianCalendar end = new GregorianCalendar();
end.setTime(endtime);
- String meetingId = handler.addNewMeeting(start, end,
- point.getAppointmentName(), atts, subject,
attendeeList,
- point.getIcalId(), jNameTimeZone);
+ handler.addNewMeeting(start, end, point.getAppointmentName(),
atts,
+ subject, attendeeList, point.getIcalId(),
jNameTimeZone);
log.debug(handler.getICalDataAsString());
- MailHandler.sendIcalMessage(email, subject,
- handler.getIcalAsByteArray(), message);
+ mailiCalThread.doSend(email, subject,
handler.getIcalAsByteArray(),
+ message);
return null;
}
@@ -842,8 +842,8 @@
log.debug(handler.getICalDataAsString());
- MailHandler.sendIcalMessage(email, subject,
- handler.getIcalAsByteArray(), template);
+ mailiCalThread.doSend(email, subject,
handler.getIcalAsByteArray(),
+ template);
return "success";
// return MailHandler.sendMail(email, subject,
template);
=======================================
---
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailHandler.java
Sun Aug 14 04:56:25 2011
+++
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailHandler.java
Sun Aug 14 09:31:35 2011
@@ -13,10 +13,13 @@
*/
public class MailHandler {
- private static final Logger log =
Red5LoggerFactory.getLogger(MailHandler.class,
ScopeApplicationAdapter.webAppRootKey);
+ private static final Logger log = Red5LoggerFactory.getLogger(
+ MailHandler.class,
ScopeApplicationAdapter.webAppRootKey);
@Autowired
private Configurationmanagement cfgManagement;
-
+ @Autowired
+ private MailThread mailThread;
+
/**
* send mail to address
*
@@ -29,51 +32,55 @@
try {
// String smtpServer="smtp.xmlcrm.org";
- String smtpServer =
cfgManagement.getConfKey(3, "smtp_server").getConf_value();
- String smtpPort =
cfgManagement.getConfKey(3, "smtp_port").getConf_value();
+ String smtpServer = cfgManagement.getConfKey(3,
"smtp_server")
+ .getConf_value();
+ String smtpPort = cfgManagement.getConfKey(3,
"smtp_port")
+ .getConf_value();
String to = toEmail;
// String from = "[email protected]";
- String from =
cfgManagement.getConfKey(3,"system_email_addr").getConf_value();
+ String from = cfgManagement.getConfKey(3,
"system_email_addr")
+ .getConf_value();
String subject = subj;
String body = message;
-
- String emailUsername =
cfgManagement.getConfKey(3, "email_username").getConf_value();
- String emailUserpass =
cfgManagement.getConfKey(3, "email_userpass").getConf_value();
-
- //return send(smtpServer, smtpPort, to, from, subject,
body);
-
- MailThread mailThread = new MailThread(smtpServer, smtpPort, to, from,
subject, body, emailUsername, emailUserpass);
- mailThread.start();
-
+
+ String emailUsername = cfgManagement
+ .getConfKey(3,
"email_username").getConf_value();
+ String emailUserpass = cfgManagement
+ .getConfKey(3,
"email_userpass").getConf_value();
+
+ // return send(smtpServer, smtpPort, to, from, subject,
body);
+
+ mailThread.doSend(smtpServer, smtpPort, to, from,
subject, body,
+ emailUsername, emailUserpass);
+
return "success";
-
+
} catch (Exception ex) {
- log.error("[sendMail] " ,ex);
+ log.error("[sendMail] ", ex);
return "Error: " + ex;
}
}
-
-
-
-
/**
* @author o.becherer
- * @param recipients (List of valid mail adresses)
- * @param subject mailSubject
- * @param iCalMimeBody byte[] containing Icaldata
- * Sending Ical Invitation
+ * @param recipients
+ * (List of valid mail adresses)
+ * @param subject
+ * mailSubject
+ * @param iCalMimeBody
+ * byte[] containing Icaldata Sending Ical Invitation
*/
-
//---------------------------------------------------------------------------------------------
- public static void sendIcalMessage(String recipients, String subject,
byte[] iCalMimeBody, String htmlBody) throws Exception{
- log.debug("sendIcalMessage");
-
-
- MailiCalThread mailiCalThread = new MailiCalThread(recipients, subject,
iCalMimeBody, htmlBody);
-
- mailiCalThread.start();
-
- }
-
//---------------------------------------------------------------------------------------------
-
-}
+ //
---------------------------------------------------------------------------------------------
+ // public static void sendIcalMessage(String recipients, String subject,
+ // byte[] iCalMimeBody, String htmlBody) throws Exception {
+ // log.debug("sendIcalMessage");
+ //
+ // MailiCalThread mailiCalThread = new MailiCalThread(recipients,
subject,
+ // iCalMimeBody, htmlBody);
+ //
+ // mailiCalThread.start();
+ //
+ // }
+ //
---------------------------------------------------------------------------------------------
+
+}
=======================================
---
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailThread.java
Fri Aug 12 11:20:41 2011
+++
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailThread.java
Sun Aug 14 09:31:35 2011
@@ -16,124 +16,142 @@
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
-
-public class MailThread extends Thread {
-
- private static final Logger log =
Red5LoggerFactory.getLogger(MailHandler.class,
ScopeApplicationAdapter.webAppRootKey);
+import org.springframework.core.task.TaskExecutor;
+
+public class MailThread {
+
+ private static final Logger log = Red5LoggerFactory.getLogger(
+ MailHandler.class,
ScopeApplicationAdapter.webAppRootKey);
+
@Autowired
private Configurationmanagement cfgManagement;
-
- private String smtpServer;
- private String smtpPort;
- private String to;
- private String from;
- private String subject;
- private String body;
- private String emailUsername;
- private String emailUserpass;
-
- public MailThread(String smtpServer, String smtpPort, String to,
+
+ private final TaskExecutor taskExecutor;
+
+ public MailThread(TaskExecutor taskExecutor) {
+ this.taskExecutor = taskExecutor;
+ }
+
+ public void doSend(String smtpServer, String smtpPort, String to,
String from, String subject, String body, String
emailUsername,
String emailUserpass) {
- super();
- this.smtpServer = smtpServer;
- this.smtpPort = smtpPort;
- this.to = to;
- this.from = from;
- this.subject = subject;
- this.body = body;
- this.emailUsername = emailUsername;
- this.emailUserpass = emailUserpass;
+
+ this.taskExecutor.execute(new MailSenderTask(smtpServer,
smtpPort, to,
+ from, subject, body, emailUsername,
emailUserpass));
+
}
- public void run() {
- try {
-
- this.send();
-
- } catch (Exception err) {
- log.error("MailThread ", err);
- }
- }
-
- /**
- * Sending a mail with given values.<br>
- * If the parameter "emailUsername" and "emailUserpass" is exist, use
SMTP Authentication.
- *
- * @param smtpServer
- * @param to
- * @param from
- * @param subject
- * @param body
- * @param emailUsername
- * @param emailUserpass
- * @return
- */
- public String send() {
- try {
-
- log.debug("Message sending in progress");
- log.debug(" From: " + from);
- log.debug(" To: " + to);
- log.debug(" Subject: " + subject);
-
- Properties props = System.getProperties();
-
- // -- Attaching to default Session, or we could start a
new one --
- //smtpPort 25 or 587
- props.put("mail.smtp.host", smtpServer);
- props.put("mail.smtp.port", smtpPort);
-
- Configuration conf =
cfgManagement.getConfKey(3, "mail.smtp.starttls.enable");
- if (conf != null) {
- if (conf.getConf_value().equals("1")){
-
props.put("mail.smtp.starttls.enable","true");
- }
- }
-
- Session session = null;
- if (emailUsername != null && emailUsername.length() > 0
- && emailUserpass != null &&
emailUserpass.length() > 0) {
- //use SMTP Authentication
- props.put("mail.smtp.auth", "true");
- session = Session.getDefaultInstance(props,
- new SmtpAuthenticator());
- }else{
- //not use SMTP Authentication
- session = Session.getDefaultInstance(props,
null);
- }
-
-
- // -- Create a new message --
- Message msg = new MimeMessage(session);
-
- // -- Set the FROM and TO fields --
- msg.setFrom(new InternetAddress(from));
- msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(
- to, false));
-
- // -- We could include CC recipients too --
- // if (cc != null)
- // msg.setRecipients(Message.RecipientType.CC
- // ,InternetAddress.parse(cc, false));
-
- // -- Set the subject and body text --
- msg.setSubject(subject);
- msg.setDataHandler(new DataHandler(new
ByteArrayDataSource(body,
- "text/html; charset=\"utf-8\"")));
-
- // -- Set some other header information --
- msg.setHeader("X-Mailer", "XML-Mail");
- msg.setSentDate(new Date());
-
- // -- Send the message --
- Transport.send(msg);
-
- return "success";
- } catch (Exception ex) {
- log.error("[mail send] " ,ex);
- return "Error" + ex;
- }
- }
-
-}
+ private class MailSenderTask implements Runnable {
+
+ private final String smtpServer;
+ private final String smtpPort;
+ private final String to;
+ private final String from;
+ private final String subject;
+ private final String body;
+ private final String emailUsername;
+ private final String emailUserpass;
+
+ public MailSenderTask(String smtpServer, String smtpPort,
String to,
+ String from, String subject, String body,
String emailUsername,
+ String emailUserpass) {
+ this.smtpServer = smtpServer;
+ this.smtpPort = smtpPort;
+ this.to = to;
+ this.from = from;
+ this.subject = subject;
+ this.body = body;
+ this.emailUsername = emailUsername;
+ this.emailUserpass = emailUserpass;
+ }
+
+ public void run() {
+ this.send();
+ }
+
+ /**
+ * Sending a mail with given values.<br>
+ * If the parameter "emailUsername" and "emailUserpass" is
exist, use
+ * SMTP Authentication.
+ *
+ * @param smtpServer
+ * @param to
+ * @param from
+ * @param subject
+ * @param body
+ * @param emailUsername
+ * @param emailUserpass
+ * @return
+ */
+ public String send() {
+ try {
+
+ log.debug("Message sending in progress");
+ log.debug(" From: " + from);
+ log.debug(" To: " + to);
+ log.debug(" Subject: " + subject);
+
+ Properties props = System.getProperties();
+
+ // -- Attaching to default Session, or we could
start a new one
+ // --
+ // smtpPort 25 or 587
+ props.put("mail.smtp.host", smtpServer);
+ props.put("mail.smtp.port", smtpPort);
+
+ Configuration conf = cfgManagement.getConfKey(3,
+ "mail.smtp.starttls.enable");
+ if (conf != null) {
+ if (conf.getConf_value().equals("1")) {
+ props.put("mail.smtp.starttls.enable",
"true");
+ }
+ }
+
+ Session session = null;
+ if (emailUsername != null &&
emailUsername.length() > 0
+ && emailUserpass != null &&
emailUserpass.length() > 0) {
+ // use SMTP Authentication
+ props.put("mail.smtp.auth", "true");
+ session = Session
+
.getDefaultInstance(props, new SmtpAuthenticator(
+
emailUsername, emailUserpass));
+ } else {
+ // not use SMTP Authentication
+ session =
Session.getDefaultInstance(props, null);
+ }
+
+ // -- Create a new message --
+ Message msg = new MimeMessage(session);
+
+ // -- Set the FROM and TO fields --
+ msg.setFrom(new InternetAddress(from));
+ msg.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to,
false));
+
+ // -- We could include CC recipients too --
+ // if (cc != null)
+ // msg.setRecipients(Message.RecipientType.CC
+ // ,InternetAddress.parse(cc, false));
+
+ // -- Set the subject and body text --
+ msg.setSubject(subject);
+ msg.setDataHandler(new DataHandler(new
ByteArrayDataSource(
+ body, "text/html;
charset=\"utf-8\"")));
+
+ // -- Set some other header information --
+ msg.setHeader("X-Mailer", "XML-Mail");
+ msg.setSentDate(new Date());
+
+ // -- Send the message --
+ Transport.send(msg);
+
+ return "success";
+ } catch (Exception ex) {
+ log.error("[mail send] ", ex);
+ return "Error" + ex;
+ }
+ }
+
+ }
+
+}
=======================================
---
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailiCalThread.java
Fri Aug 12 11:20:41 2011
+++
/branches/dev/injection/src/app/org/openmeetings/utils/mail/MailiCalThread.java
Sun Aug 14 09:31:35 2011
@@ -1,7 +1,6 @@
package org.openmeetings.utils.mail;
import java.io.ByteArrayInputStream;
-import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
@@ -21,109 +20,142 @@
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.task.TaskExecutor;
public class MailiCalThread extends Thread {
-
- private static final Logger log =
Red5LoggerFactory.getLogger(MailiCalThread.class,
ScopeApplicationAdapter.webAppRootKey);
+
+ private static final Logger log = Red5LoggerFactory.getLogger(
+ MailiCalThread.class,
ScopeApplicationAdapter.webAppRootKey);
+
@Autowired
private Configurationmanagement cfgManagement;
-
- private String recipients;
- private String subject;
- private byte[] iCalMimeBody;
- private String htmlBody;
-
- public MailiCalThread(String recipients, String subject,
- byte[] iCalMimeBody, String htmlBody) {
- super();
- this.recipients = recipients;
- this.subject = subject;
- this.iCalMimeBody = iCalMimeBody;
- this.htmlBody = htmlBody;
- }
-
- public void run() {
- try {
-
- this.sendIcalMessage();
-
- } catch (Exception err) {
- log.error("MailThread ", err);
- }
- }
-
- /**
- * @author o.becherer
- * @param recipients (List of valid mail adresses)
- * @param subject mailSubject
- * @param iCalMimeBody byte[] containing Icaldata
- * Sending Ical Invitation
- */
-
//---------------------------------------------------------------------------------------------
- public void sendIcalMessage() throws Exception{
- log.debug("sendIcalMessage");
-
-
- // Evaluating Configuration Data
- String smtpServer =
cfgManagement.getConfKey(3, "smtp_server").getConf_value();
- String smtpPort =
cfgManagement.getConfKey(3, "smtp_port").getConf_value();
- // String from = "[email protected]";
- String from =
cfgManagement.getConfKey(3,"system_email_addr").getConf_value();
-
- String emailUsername =
cfgManagement.getConfKey(3, "email_username").getConf_value();
- String emailUserpass =
cfgManagement.getConfKey(3, "email_userpass").getConf_value();
-
- Properties props = System.getProperties();
-
- props.put("mail.smtp.host", smtpServer);
- props.put("mail.smtp.port", smtpPort);
-
- Configuration conf =
cfgManagement.getConfKey(3, "mail.smtp.starttls.enable");
- if (conf != null) {
- if (conf.getConf_value().equals("1")){
- props.put("mail.smtp.starttls.enable","true");
+
+ private final TaskExecutor taskExecutor;
+
+ public MailiCalThread(TaskExecutor taskExecutor) {
+ this.taskExecutor = taskExecutor;
+ }
+
+ public void doSend(String recipients, String subject, byte[]
iCalMimeBody,
+ String htmlBody) {
+
+ this.taskExecutor.execute(new MailSenderTask(recipients,
subject,
+ iCalMimeBody, htmlBody));
+
+ }
+
+ private class MailSenderTask implements Runnable {
+
+ private final String recipients;
+ private final String subject;
+ private final byte[] iCalMimeBody;
+ private final String htmlBody;
+
+ public MailSenderTask(String recipients, String subject,
+ byte[] iCalMimeBody, String htmlBody) {
+ super();
+ this.recipients = recipients;
+ this.subject = subject;
+ this.iCalMimeBody = iCalMimeBody;
+ this.htmlBody = htmlBody;
+ }
+
+ public void run() {
+ try {
+
+ this.sendIcalMessage();
+
+ } catch (Exception err) {
+ log.error("MailSenderTask ", err);
}
}
-
- // Check for Authentification
- Session session = null;
- if (emailUsername != null && emailUsername.length() > 0
- && emailUserpass != null && emailUserpass.length()
> 0) {
- //use SMTP Authentication
- props.put("mail.smtp.auth", "true");
- session = Session.getDefaultInstance(props,
- new SmtpAuthenticator());
- }else{
- //not use SMTP Authentication
- session = Session.getDefaultInstance(props, null);
- }
-
- // Building MimeMessage
- MimeMessage mimeMessage = new MimeMessage(session);
- mimeMessage.setSubject(subject);
- mimeMessage.setFrom(new InternetAddress(from));
- mimeMessage.addRecipients(Message.RecipientType.TO,
InternetAddress.parse(recipients, false));
-
- // -- Create a new message --
- BodyPart msg = new MimeBodyPart();
- msg.setDataHandler(new DataHandler(new
ByteArrayDataSource(htmlBody, "text/html; charset=\"utf-8\"")));
-
- Multipart multipart = new MimeMultipart();
-
- BodyPart iCalAttachment = new MimeBodyPart();
- iCalAttachment.setDataHandler(new DataHandler(new
javax.mail.util.ByteArrayDataSource(new
ByteArrayInputStream(iCalMimeBody), "text/calendar;method=REQUEST;charset=\"UTF-8\"")));
-
- multipart.addBodyPart(iCalAttachment);
- multipart.addBodyPart(msg);
-
- mimeMessage.setContent(multipart);
-
- // -- Set some other header information --
- //mimeMessage.setHeader("X-Mailer", "XML-Mail");
- //mimeMessage.setSentDate(new Date());
-
- //Transport trans = session.getTransport("smtp");
- Transport.send(mimeMessage);
-
+
+ /**
+ * @author o.becherer
+ * @param recipients
+ * (List of valid mail adresses)
+ * @param subject
+ * mailSubject
+ * @param iCalMimeBody
+ * byte[] containing Icaldata Sending Ical Invitation
+ */
+ //
---------------------------------------------------------------------------------------------
+ public void sendIcalMessage() throws Exception {
+ log.debug("sendIcalMessage");
+
+ // Evaluating Configuration Data
+ String smtpServer = cfgManagement.getConfKey(3,
"smtp_server")
+ .getConf_value();
+ String smtpPort = cfgManagement.getConfKey(3,
"smtp_port")
+ .getConf_value();
+ // String from = "[email protected]";
+ String from = cfgManagement.getConfKey(3,
"system_email_addr")
+ .getConf_value();
+
+ String emailUsername = cfgManagement
+ .getConfKey(3,
"email_username").getConf_value();
+ String emailUserpass = cfgManagement
+ .getConfKey(3,
"email_userpass").getConf_value();
+
+ Properties props = System.getProperties();
+
+ props.put("mail.smtp.host", smtpServer);
+ props.put("mail.smtp.port", smtpPort);
+
+ Configuration conf = cfgManagement.getConfKey(3,
+ "mail.smtp.starttls.enable");
+ if (conf != null) {
+ if (conf.getConf_value().equals("1")) {
+ props.put("mail.smtp.starttls.enable",
"true");
+ }
+ }
+
+ // Check for Authentification
+ Session session = null;
+ if (emailUsername != null && emailUsername.length() > 0
+ && emailUserpass != null &&
emailUserpass.length() > 0) {
+ // use SMTP Authentication
+ props.put("mail.smtp.auth", "true");
+ session = Session.getDefaultInstance(props,
+ new
SmtpAuthenticator(emailUsername, emailUserpass));
+ } else {
+ // not use SMTP Authentication
+ session = Session.getDefaultInstance(props,
null);
+ }
+
+ // Building MimeMessage
+ MimeMessage mimeMessage = new MimeMessage(session);
+ mimeMessage.setSubject(subject);
+ mimeMessage.setFrom(new InternetAddress(from));
+ mimeMessage.addRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(recipients,
false));
+
+ // -- Create a new message --
+ BodyPart msg = new MimeBodyPart();
+ msg.setDataHandler(new DataHandler(new
ByteArrayDataSource(
+ htmlBody, "text/html;
charset=\"utf-8\"")));
+
+ Multipart multipart = new MimeMultipart();
+
+ BodyPart iCalAttachment = new MimeBodyPart();
+ iCalAttachment.setDataHandler(new DataHandler(
+ new javax.mail.util.ByteArrayDataSource(
+ new
ByteArrayInputStream(iCalMimeBody),
+
"text/calendar;method=REQUEST;charset=\"UTF-8\"")));
+
+ multipart.addBodyPart(iCalAttachment);
+ multipart.addBodyPart(msg);
+
+ mimeMessage.setContent(multipart);
+
+ // -- Set some other header information --
+ // mimeMessage.setHeader("X-Mailer", "XML-Mail");
+ // mimeMessage.setSentDate(new Date());
+
+ // Transport trans = session.getTransport("smtp");
+ Transport.send(mimeMessage);
+
+ }
+
}
}
=======================================
---
/branches/dev/injection/src/app/org/openmeetings/utils/mail/SmtpAuthenticator.java
Fri Aug 12 11:20:41 2011
+++
/branches/dev/injection/src/app/org/openmeetings/utils/mail/SmtpAuthenticator.java
Sun Aug 14 09:31:35 2011
@@ -3,27 +3,25 @@
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
-import org.openmeetings.app.data.basic.Configurationmanagement;
-import org.springframework.beans.factory.annotation.Autowired;
-
/**
*
* @author swagner
- *
+ *
*/
-public class SmtpAuthenticator extends Authenticator{
- @Autowired
- private Configurationmanagement cfgManagement;
-
+public class SmtpAuthenticator extends Authenticator {
+
+ private final String username;
+ private final String password;
+
+ public SmtpAuthenticator(String emailUsername, String emailUserpass) {
+ this.username = emailUsername;
+ this.password = emailUserpass;
+ }
+
@Override
public PasswordAuthentication getPasswordAuthentication() {
- //String username = "[email protected]";
- String username =
cfgManagement.getConfKey(3, "email_username").getConf_value();
- //String password = "tony123";
- String password =
cfgManagement.getConfKey(3, "email_userpass").getConf_value();
-
- return new PasswordAuthentication(username,password);
+
+ return new PasswordAuthentication(username, password);
}
-
-}
+}
--
You received this message because you are subscribed to the Google Groups
"OpenMeetings developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/openmeetings-dev?hl=en.