Cannot send email with attachment on application server

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

Cannot send email with attachment on application server

Postby herakles86 » Wed Nov 19, 2014 9:04 am

Hi, guys,

i meet a very weird thing this morning, I use mail plugin to send the email on servoy version 7.4.1.

The sending email function works beautifully on developer.
On the sever, if I send an only html contnet email, it works good.
But if i try to send an email with some attachments, no matter the attachment is embedded or not, the application will log an exception:
Code: Select all
javax.mail.MessagingException: IOException while sending message;
    nested exception is:
   javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;


It is so strange, here is the sample code i used for testing.

Code: Select all
function onActionSendEmailTest(event) {
   var attachments = new Array();
   var att1 = plugins.file.convertToJSFile('c:\\mailmsg.txt');
   attachments.push(plugins.mail.createBinaryAttachment('mailmsg.txt', att1.getBytes(), att1.getContentType()));
   var att2 = plugins.file.convertToJSFile('c:\\1.jpg');
   attachments.push(plugins.mail.createBinaryAttachment('1.jpg', att2.getBytes(), att2.getContentType()));
   var success = plugins.mail.sendMail('to@emailaddress.com', 'from@emailaddress.com', '1111', '<html><body><p>111</p><img src="%%1.jpg%%"></body></html>', null, null, attachments, ["mail.smtp.host=192.168.0.100","mail.smtp.port=25","mail.smtp.auth=false","mail.smtp.username=","mail.smtp.password=","mail.smtp.starttls.enable=false"]);
   if (!success) {
      application.output('------------------------------------------>error: '+plugins.mail.getLastSendMailExceptionMsg());
   } else {
      application.output('------------------------------------------>success');
   }
}


Is there anything wrong with my code? Does anyone meet the same problem before?
I really need your help.

BTW, is there any way I can debug the mail plugin? I just want to see the mail message the plugin built, I suspect the problem happened when building the message.

Thank you very much, guys.
Anping Wang

TSM (The Service Manager)
Australia
herakles86
 
Posts: 14
Joined: Mon Aug 25, 2014 1:30 am

Re: Cannot send email with attachment on application server

Postby herakles86 » Wed Dec 03, 2014 5:50 am

I added some sniffer code in the source code below:

in com.servoy.extensions.plugins.mail.MailServer

Code: Select all
         String dateStr = new SimpleDateFormat("ddMMyyyy-HHmmss").format(new Date());
         File mailpartmsg = new File("c:\\mail_mixedpart"+dateStr+".txt");
          try {
             mixedMultipart.writeTo(new FileOutputStream(mailpartmsg));
         } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         
         message.setContent(mixedMultipart);
         
         dateStr = new SimpleDateFormat("ddMMyyyy-HHmmss").format(new Date());
         File mailmsg = new File("c:\\mailmsg"+dateStr+".txt");
          try {
            message.writeTo(new FileOutputStream(mailmsg));
         } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }


the output of my mixed multi part was shown as below:

Code: Select all
------=_Part_6_17988859.1417577097073

<html>
<head>
</head>
<body>
<p>aaa</p>
</body>
</html>
------=_Part_6_17988859.1417577097073
Content-Disposition: attachment; filename=1.jpg

[image binary code]
------=_Part_6_17988859.1417577097073--


But after the message.setContent(mixedMultipart)

I outputed the message, the message is as:

Code: Select all
Date: Wed, 3 Dec 2014 14:24:57 +1100 (EST)
From: [from email]
To: [to email]
Message-ID: <13328912.7.1417577097076.JavaMail.SYSTEM@asi2>
Subject: [subject]
MIME-Version: 1.0
Content-Type: multipart/mixed;
   boundary="----=_Part_6_17988859.1417577097073"


These two outputs seen that the plugin failed to set the content of the mixed multi part.

Does anyone meet this problem before?

Thank you very much.
Anping Wang

TSM (The Service Manager)
Australia
herakles86
 
Posts: 14
Joined: Mon Aug 25, 2014 1:30 am

Re: Cannot send email with attachment on application server

Postby herakles86 » Thu Dec 04, 2014 1:21 am

I think I find the reason.

We delete the mailcap of mail.jar when signing the jars, so that the mail plugin cannot find correct MIME Type Handler mapping configuration.

Thanks guys
Anping Wang

TSM (The Service Manager)
Australia
herakles86
 
Posts: 14
Joined: Mon Aug 25, 2014 1:30 am

Re: Cannot send email with attachment on application server

Postby palacio » Tue Feb 13, 2018 12:00 pm

Thanks to this topic we had resolved our problem.

It was really because of the file "mailcap" , if this file is missing you'll have a big problem.

The files that you should look at are:

application_server
1. lib/activation.jar
2. lib/mail.jar
3. plugins/drmaison-lib/activation.jar
4. plugins/drmaison-lib/mail.jar

Thank you!!

palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 4 guests

cron