The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.
JAVA - STRUTS2
package com.action;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import com.opensymphony.xwork2.Action;
import com.bo.LoginBo;
import com.manager.AttendanceManager;
import com.manager.LoginManager;
import com.manager.SSLEmail;
import com.vo.AttendanceManagementVo;
import com.vo.LeaveManagementVo;
import com.vo.LoginVo;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;
public class InsertApplyLeaveAction implements Action {
private AttendanceManagementVo attendanceManagementVo;
public AttendanceManagementVo getAttendanceManagementVo() {
return attendanceManagementVo;
}
public void setAttendanceManagementVo(
AttendanceManagementVo attendanceManagementVo) {
this.attendanceManagementVo = attendanceManagementVo;
}
#Override
public String execute() throws Exception {
String empId=attendanceManagementVo.getEmpId();
String leaveType=attendanceManagementVo.getLeaveType();
String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
String reason=attendanceManagementVo.getReason();
String employeeName=attendanceManagementVo.getEmployeeName();
String manageEmployeeId=empId;
float totalLeave=attendanceManagementVo.getTotalLeave();
String leaveStatus=attendanceManagementVo.getLeaveStatus();
// String approverId=attendanceManagementVo.getApproverId();
attendanceManagementVo.setEmpId(empId);
attendanceManagementVo.setLeaveType(leaveType);
attendanceManagementVo.setLeaveStartDate(leaveStartDate);
attendanceManagementVo.setLeaveEndDate(leaveEndDate);
attendanceManagementVo.setReason(reason);
attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
attendanceManagementVo.setTotalLeave(totalLeave);
attendanceManagementVo.setLeaveStatus(leaveStatus);
attendanceManagementVo.setEmployeeName(employeeName);
AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
AttendanceManager attendanceManager=new AttendanceManager();
attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
String approverId=attendanceManagementVo1.getApproverId();
String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
LoginVo loginVo=new LoginVo();
LoginManager loginManager=new LoginManager();
loginVo.setEmpId(approverId);
loginVo=loginManager.getEmailAddress(loginVo);
String emailAddress=loginVo.getEmailAddress();
String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
// String body = "Hi "+approverEmployeeName+" ," + "\n" + "\n" +
// leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "\n" + "\n" +
// " Employee Name: " + employeeName +"\n" +
// " Applied Leave Type: " + leaveType +"\n" +
// " Total Days: " + totalLeave +"\n" + "\n" +
// " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "\n" +
// " NOTE : This is an automated message. Please do not reply."+ "\n" + "\n" +
Session session = Session.getInstance(null, null);
MimeBodyPart messageBodyPart = new MimeBodyPart();
MimeMessage message = new MimeMessage(session);
Multipart multipart = new MimeMultipart();
String htmlText = ("<div style=\"color:red;\">BRIDGEYE</div>");
messageBodyPart.setContent(htmlText, "text/html");
loginVo.setHtmlBody(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
loginVo.setSubject(subject);
// loginVo.setBody(body);
loginVo.setEmailAddress(emailAddress);
SSLEmail sSSEmail=new SSLEmail();
sSSEmail.sendEmail(loginVo);
return "success";
}
}
If we comment that "loginVo.setHtmlBody(messageBodyPart);" part from coding and uncomment the "String body" means email is sending properly with a plain text.
By using the Above code as like it means it showing the
Struts has detected an unhandled exception: Messages: File: javax/mail/Session.java Line number: 206 "ABOVE IS A ERROR SHOWING WHILE RUNNING THE CODE"
To send your message as HTML you should do something
messageBodyPart = new MimeBodyPart();
String htmlText = body.replaceAll("\n","<br>");
messageBodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
Related
at the moment I'm encountering a problem which I really don't understand. I have a class inside a OSGI-Plugin, which also contains javax.mail-1.6.2.jar as bundled classpath inside the osgi-plugins lib folder. When I run the code with a simple main-method on my machine, everything works. The mail contains all parts and end correct. But when I run the plugin inside our third-party application, JavaMail suddenly stops the output after the first boudary. No exception is raised, no logmessage,it just ends output and continues.
Date: Sun, 13 Jun 2021 10:05:26 +0200 (CEST)
From: noreply#localhost.com
Reply-To: noreply#localhost.com
To: test#nodomain.com
Message-ID: <126209092.01623571526344.JavaMail.LOCALHOST$#LOCALHOST>
Subject: =?utf-8?Q?#web#_[TEST]=C2=A0Tesfall_zu_?=
=?utf-8?Q?javamail_(test#nodomain.com)?=
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_185595348.1623571526344"
Thats it. It's just empty.
I already reduced the error sources, the output is the same (truncated) mail, when I save it. So its not the smtp-gateway or any smtp setting. And now I don't have any idea left, where to look next. I cannot debug the class on the third-party application, where it got loaded (Oracle Java SE 1.8 HotspotVM). Does anyone has any idea what could be a cause or how to narrow the cause?
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.mail.internet.MimeMultipart;
public class DocumentToSmtp {
public void process() throws Exception {
String mailhost = "localhost";
String port = "25";
//Get SMTP output to logger
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final String utf8 = StandardCharsets.UTF_8.name();
try (PrintStream ps = new PrintStream(baos, true, utf8)) {
try {
boolean authification = false;
String prot = "smtp";
Properties props = System.getProperties();
if (mailhost != null) {
props.put("mail." + prot + ".host", mailhost);
props.put("mail." + prot + ".port", port);
}
props.put("mail." + prot + ".auth", authification);
Session session = Session.getInstance(props, null);
session.setDebug(true);
session.setDebugOut(ps);
MimeMessage msg = new MimeMessage(session);
String to = "test#nodomain.com";
msg.addRecipients(RecipientType.TO, InternetAddress.parse(to, false));
msg.addFrom(InternetAddress.parse("noreply#localhost.com", false));
String subject = "#web# [TEST] Tesfall zu javamail (test#nodomain.com)";
msg.setSubject(subject, "utf-8");
String replyto = "noreply#localhost.com";`
//originally the class contained multiple attachment as pdfs, but
List<MimeBodyPart> bodies = new ArrayList<>();
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
String text = "<!DOCTYPE html><html style=\"margin: 0; font-family: Arial; font-size: 14px\">\r\n"
+ " <head>\r\n"
+ " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n"
+ " <title>EMail</title>\r\n"
+ " <style type=\"text/css\"> /* common */\r\n"
+ " html, body {\r\n"
+ " margin: 0;\r\n"
+ " font-family: Arial;\r\n"
+ " font-size: 14px;\r\n"
+ " }\r\n"
+ " </style>\r\n"
+ " </head>\r\n"
+ " <body style=\"margin: 0; font-family: Arial; font-size: 14px\">\r\n Guten Tag!"
+ " </body>\r\n"
+ " </html>";
mbp1.setHeader("Content-Transfer-Encoding", "8bit");
mbp1.setContent(text, "text/html; charset=utf-8"); //5
bodies.add(mbp1);
//add the parts to multi-part
Multipart mp = new MimeMultipart();
for (MimeBodyPart mbp : bodies) {
mp.addBodyPart(mbp);
}
msg.setContent(mp);
msg.setSentDate(new Date());
msg.writeTo(new FileOutputStream(new File("%TEMP%/test.eml")));
Transport.send(msg);
} finally {
//Print logmessages.
String data = baos.toString(utf8);
System.out.println(data);
}
}
}
}
OSGI Manifest
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.6
Created-By: 1.8.0_60-b27 (Oracle Corporation)
Bundle-ClassPath: .,
commons-codec-1.3.jar,
commons-codec-1.9.jar,
commons-lang3-3.3.1.jar,
commons-httpclient-3.1.jar,
commons-io-2.4.jar,
commons-logging-1.1.3.jar,
javax.mail-1.6.2.jar
Bundle-Version: 42324
Bundle-ManifestVersion: 2
Bundle-SymbolicName: DocumentPlugins
Export-Service: de.documentworkflow.plugins.DocumentToSMTP
Import-Package: javax.activation,
javax.crypto,
javax.crypto.spec,
javax.imageio,
javax.imageio.plugins.jpeg,
javax.imageio.stream,
javax.net,
javax.net.ssl,
javax.xml.bind,
javax.xml.bind.annotation,
javax.xml.datatype,
javax.xml.namespace,
javax.xml.soap,
javax.xml.transform,
javax.xml.ws,
javax.xml.ws.handler.soap
Embed-Dependency: commons-codec;scope=compile|runtime
Built-Date: 2020-06-13_07-07-54
Built-By: jenkins
Implementation-Version: 1706
Svn-Revision: 42323
Bundle-Vendor: test
Class-Path: posy-documentworkflow-interface-api-1
.0.42323.jar commons-codec-1.9.jar trove-3.0.1.jar log4j-1.2.15.jar m
ail-1.4.3.jar commons-net-3.3.jar jsch-0.1.53.jar guava-11.0.2.jar jd
om.jar xsom.jar relaxngDatatype.jar javax.mail-1.6.2.jar
Require-Capability: osgi.ee
Best regards.
Below exception is coming
Exception: java.lang.RuntimeException:
java.lang.ClassNotFoundException:
org.glassfish.jersey.internal.RuntimeDelegateImpl Message:
java.lang.RuntimeException: java.lang.ClassNotFoundException:
org.glassfish.jersey.internal.RuntimeDelegateImpl
Code
package com.hoja;
import java.io.File;
import java.io.FilePermission;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder;
public class BhaiHoja {
#Produces("application/pdf")
public Response getFile(String policyNo, String docId){
String constFilePath = "C:/Users/Anushree/Desktop/Webservice/";
String flow = (constFilePath + "/" + policyNo + "/" + docId +".pdf");
File fileNew = new File(constFilePath + "/" + policyNo + "/" + docId +".pdf");
File FilePath = new File("C:/Users/Anushree/Desktop/Webservice/"); FilePermission permission = new FilePermission(flow, "read"); ResponseBuilder
res = Response.ok((Object)fileNew );
res.header("content-disposition","attachment;filename=fileNew");
return res.build();
}
}
I am sending mail in with a excel attachment file through JAVA mail. Whenever i send the email to a IMAP email box it's filename gets changed to Untitled attachment as oppose to name i am passing for other email boxes it works file.
I have contacted my email provided and they suspect it is formatting issue as JAVa mail by default formats in RFC 2231, for IMAP it has to be RFC 2047/2231.
Note: application is deployed on Widfly 9 using JAVA 8.
This is how i call the method:
ByteArrayOutputStream baos = new ByteArrayOutputStream(excel_bytes.length);
baos.write(excel_bytes, 0, excel_bytes.length);
DataSource aAttachment = new ByteArrayDataSource(baos.toByteArray(),"application/vnd.ms-excel");
String to_email = tenant.getEmail();
email.sendRechargeBillEmail(to_email, aAttachment, file_name + ".xlsx",tenant.getCompanyName(), String.valueOf(job.getStartDate()), String.valueOf(job.getEndDate()));
This is the class which does have the email methods:
package com.nextcontrols.rechargecalculation;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
public class SendAttachmentInEmail {
private static final Logger logger =
Logger.getLogger(SendAttachmentInEmail.class.getCanonicalName());
public void sendEmail(String to_email, DataSource attachment, String
file_name, String from_email, String user_name, String password, String
email_body, String email_subject) {
Properties props = new Properties();
props.put("mail.smtp.host", "mail2.nextcontrols.local");
Session session = Session.getDefaultInstance(props);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from_email));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to_email));
message.setSubject(email_subject);
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(email_body, "text/html; charset=utf-8");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
MimeBodyPart mailattachment = new MimeBodyPart();
DataSource source = attachment;
mailattachment.setFileName(file_name);
mailattachment.setDataHandler(new DataHandler(source));
mailattachment.setDisposition(MimeBodyPart.ATTACHMENT);
multipart.addBodyPart(mailattachment);
message.setContent(multipart);
Transport.send(message);
logger.info("////// Sent message successfully to "+ to_email);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
public void sendRechargeBillEmail(String to_email, DataSource attachment, String file_name,String tenant_name, String start_date, String end_date){
String subject = "Billing - " + tenant_name + " - " + start_date + " to " + end_date;
String bodyText = "Please find attached your utility recharge bill for " + start_date + " to " + end_date;
String note = "<i>This is an automated email, please do not reply to this address</i>";
String fromText = "Regards,<br />-- <br />";
String disclaimerTop = "Privacy and Confidentiality Notice";
String disclaimerDown = " txt";
bodyText = bodyText + "<br /> <br /> <br />" + note + "<br />" + fromText + "<br />" + addColor (disclaimerTop, Color.GRAY ,"2") + "<br />" + addColor(disclaimerDown, Color.GRAY, "1");
sendEmail(to_email, attachment, file_name, "noreply#nxt.com", "Billing", "billing", bodyText, subject);
}
public static String addColor(String msg, Color color, String size) {
String hexColor = String.format("#%06X", (0xFFFFFF & color.getRGB()));
String colorMsg = "<FONT size = \" "+ size +"\" COLOR=\"" + hexColor + "\">" + msg + "</FONT>";
return colorMsg;
}
}
If your IMAP server is changing the file name because it doesn't understand RFC 2231, then it really needs to be updated. RFC 2231 is 20 years old.
You can disable the use of RFC 2231 to encode the file name by setting the JavaMail System property mail.mime.encodeparameters to "false".
Can any one help me with a java code where i want that my html code to be added in body of the mail and the mail client should pop up so that a person can enter the To: and can edit the body if needed.
I have tried this code but this one just sends the mail.What i want is the my mail client should popup with body already entered.
package you;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
public class test1 {
public void fnSendMail(String Status) throws IOException, InvalidFormatException, URISyntaxException {
String htmlContent = null;
if (Status.equals("Completed")) {
htmlContent = "<html><br>Below is Test Execution Report.<br>Please find the attached for Detailed Results"
+ "<br><br><table border='1' cellpadding='2' cellspacing='3' width='40%' bordercolor='#999999' style='border-collapse: collapse;'>"
+ "<tr><th>SNo</th><th>Run_Method</th><th>abc_name</th><th>Execution_Status</th></tr>" + "</table>"
+ "<br><br><br><h3 style='color:FireBrick;'>Please do not respond to this mail </h3></html>";
} else {
htmlContent = "<html><br>" + "<h3 style='color:FireBrick;'>Automation got failed due to some issue, hence "
+ "Please verify Maven Errors.<br><br>Execution Status till failure is attached.</h3></html>";
}
String from = "abc#cdf.com";
String host = "x.y.z";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
Multipart multipart = new MimeMultipart();
BodyPart messageBodyText = new MimeBodyPart();
message.setSubject("CSI API Automated Testing Report is " + Status);
messageBodyText.setContent(htmlContent, "text/html");
multipart.addBodyPart(messageBodyText);
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
public static void main(String[] args) {
test1 test2= new test1();
try {
test2.fnSendMail("Completed");
System.out.println("Email sent.");
} catch (Exception ex) {
System.out.println("Failed to sent email.");
ex.printStackTrace();
}
}
}
Any other way to do this will also work, but i need is java and javascript only
Instead of calling Transport.send you have to call MimeMessage.saveChanges then use MimeMessage.writeTo to save it to the filesystem as '.eml'. Then open that file with java.awt.Desktop.open to launch the email client. Your system must have a mime association with eml or the open call will fail.
If the O/S mime type for eml is not set to something like outlook.exe /eml %1 then you might have to resort to using the process API to launch outlook directly using the eml switch. For example, if you want to preview the foo.eml draft message then the command would be:
outlook.exe /eml foo.eml
You'll have to handle clean up after the email client is closed.
You also have to think about the security implications of email messages being left on the file system.
I am working on Oracle MAF app and using Java mail API for sending outlook meeting requests. I can successfully send mail from java command-line, but when trying same using Mobile app, the code doesn't go after where creating "MimeMessage" class object.
MimeMessage message = new MimeMessage(mailSession);
printStackTrace() shows this exception:
06-09 10:54:43.146: D/JVM(16075): [SEVERE - oracle.adfmf.framework -
Utility - invoke] InvocationTargetException Error: ERROR
[oracle.adfmf.framework.exception.AdfException] - Error invoking
method 'sendMail' in 'class beans.UtilBean'
06-09 12:14:07.466: I/System.out(3760): [SEVERE -
oracle.adfmf.framework - adf.mf.internal - logError] Request:
{"classname":"oracle.adfmf.framework.api.Model","method":"processBatchRequests","params":[false,[{"classname":"oracle.adfmf.framework.api.Model","method":"evaluateMethodExpression","params":["#{UtilBean.sendMail}",[{".type":"oracle.adfmf.amx.event.ActionEvent"}],"void",["oracle.adfmf.amx.event.ActionEvent"]]}]]}
exception: {"message":"Error invoking method 'sendMail' in 'class
beans.UtilBean'",".exception":true,"severity":"ERROR",".type":"oracle.adfmf.framework.exception.AdfException"}
Full source code of my class is here:
package beans;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import oracle.adfmf.amx.event.ActionEvent;
public class Email {
private static final String SMTP_HOST_NAME = "mail_host_name";
private static final String SMTP_AUTH_USER = "smtp_user_id";
private static final String SMTP_AUTH_PWD = "smtp_auth_pass";
private static final String SMTP_AUTH_PORT = "smtp_port";
private static final String MAIL_FROM_ADDRESS = "from_addr";
private static final String RECEIPENT_1 = "receipent_1_addr";
private static final String RECEIPENT_2 = "receipent_2_addr";
public void sendEmail(ActionEvent actionEvent) {
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", SMTP_AUTH_PORT);
Authenticator auth = new SMTPAuthenticator();
//Get the session object
Session mailSession = Session.getDefaultInstance(props, auth);
//compose message
try {
System.out.print("CALLED0"); //I can see this in Logcat Logs
MimeMessage message = new MimeMessage(mailSession); // Program stuck here
System.out.print("CALLED1");//I can not see this in Logcat Logs
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=vevent");
message.setFrom(new InternetAddress(MAIL_FROM_ADDRESS));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(RECEIPENT_1));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(RECEIPENT_2));
message.setSubject("Outlook Meeting Request Using JavaMail");
StringBuffer sb = new StringBuffer();
StringBuffer buffer =
sb.append("BEGIN:VCALENDAR\n" + "PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" + "METHOD:REQUEST\n" + "BEGIN:VEVENT\n" +
"ATTENDEE;CN=\"Attendee1\";ROLE=REQ-PARTICIPANT;MAILTO:attendee1#addendant.com\n" +
"ATTENDEE;CN=\"Attendee2\";ROLE=OPT-PARTICIPANT;MAILTO:attendee2#addendant.com\n" +
"ORGANIZER:MAILTO:org#org.com\n" + "DTSTART:20050406T073000Z\n" +
"DTEND:20050406T080000Z\n" + "LOCATION:conf\n" + "TRANSP:OPAQUE\n" + "SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E00800000000A0A742E5073AC5010000000000000000100\n" +
" 0000029606C073D82204AB6C77ACE6BC2FBE2\n" + "DTSTAMP:20050405T122004Z\n" +
"CATEGORIES:Meeting\n" + "DESCRIPTION:What are you doing?\n\n" + "SUMMARY:How are you?\n" +
"PRIORITY:5\n" + "CLASS:PUBLIC\n" + "BEGIN:VALARM\n" + "TRIGGER:PT1440M\n" +
"ACTION:DISPLAY\n" + "DESCRIPTION:Reminder\n" + "END:VALARM\n" + "END:VEVENT\n" +
"END:VCALENDAR\n");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
messageBodyPart.setContent(buffer.toString(), "text/calendar");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
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);
}
}
}
In Email class I added print statement before and after where creating "MimeMessage" class object, I am able to see first print in logcat but not second.
Deploying java project on Web logic server as a web service (as a .war package) worked for me.