Created attachment 21986 [details] Source code for JMeter SMTP-Sampler For a project, we have extended an existing implementation of a JMeter SMTP-Sampler (initially coded by Luca Maragnani, found at http://www.beolink.org/index/jmeter-plug-in). The sampler has meanwhile the following features: - SSL / StartTLS / "Plaintext" - sending-support for SMTP - Multiple recipients, including "To", "CC" and "BCC" - Multiple attachments - and more We furthermore think about an option to be able to send an ".eml"-file via the sampler, but this could at most be an additional feature for a future version. Additionally, we have not implemented any cryptographic functionality by now. It would certainly be a valuable enhancement to implement e.g. BouncyCastle X.509 or PGP-support. PLEASE NOTE: - Do not use this sampler to send mass e-mails! - Have a look at the license-file (can be found under /src/)
Please don't get frightened because of the "license-note" above - naturally, we are developing all our samplers (including this one) under apache license as all JMeter-parts!
Created attachment 22055 [details] Source code for JMeter SMTP-Sampler (with enhancements) Some enhancements and fixes for the SMTP-Sampler code: - adds support for sending eml files - adds a log of the smtp session to the sampler result - jmeter.smtpsampler.protocol.SendMailCommand.execute() used PipedInputStreams in a way that could lead to a deadlock. This was fixed.
... and no longer only compiles/runs with java6
see also bug 25355
There has been no comments on this Bug for almost 2 years. I would like to see the proposed changes in JMeter. I have tested it with SVN Head revision 946591 and it works as expected. I have moved the packages to a path similar to the Mail Reader Sampler classes, so it should be simple to add this to the current version of JMeter.
Created attachment 25469 [details] Source code for SMTP sampler
There is a slight problem with the file headers - they contain Copyright lines which need to be removed/moved: http://www.apache.org/legal/src-headers.html#header-existingcopyright So we need permission from Luca Maragnani & Michael Tschannen (or their agents) to change the source files accordingly.
Permission granted (I don't work on this project anymore but feel free to use my part of the source code), if you need to remove the copyright statement please do so.
E-mail correspondence from Luca Maragnani: > From: Luca Maragnani (luca.maragnani@gmail.com) > Sent: Friday, October 02, 2009 7:21:14 AM > > Hi Kevin, > > I'm glad that the plugin is of your interest: certainly you can remove the copyright statement in order to include the code into jmeter source tree. > > Bye, > Luca
Thanks for the very prompt responses - it will take a bit longer (!) to add the code to SVN and test it, but hopefully there will be some progress next week.
Created attachment 25470 [details] Source code for SMTP sampler witho Apache license I have removed the install certificate feature since it contained SUN Microsystems copyright. We may opt to integrate it once more in the future with an alternative code that does not have license problems.
see also bug 38387 comment 8 for how to be robust against absent bc*.jar
Created attachment 25482 [details] This patch contains a SMTPSampler with a graceful failure presentation at the GUI level when the bouncy castle jar is not present.
Sebb, do we have progress on this bug? I have some time that I can invest on any required changes on this code. Regards
Latest patch looks mostly OK. Not sure why the sampler has the "Check for failure" option. This seems out of place for a sample. There a few other tweaks that need to be made, but these can be done later. As for Bug 38387, it would be very helpful to have a patch for component_reference.xml and some unit tests, though that may be quite hard.
Could you point an existing junit test that I could use as example for the new tests?
Any chance you could provide a short description for compononent_reference.xml? I can do the screnshot, but having the text would be very useful.
Will be working on it today. Sorry for delay, got flooded with work the last weeks.
Created attachment 25658 [details] Screenshot
Created attachment 25659 [details] SMTP Documentation Patch
Documentation patch is done. If need anything else let me know. I believe that the original author is also willing to put some time into this patch: >Hi Luciana, >I confirm you can remove the copyright note in order to include the source >code into JMeter distribution. >Since there were many tentative to achieve this result, don't hesitate to >contact me in case of any problem. I would be really glad to give a little >contribute to the project. >Regards. >Luca I will call his attention to this rfe via e-mail once again since he is not registered in the bugzilla platform.
I've started working on adding the code, however I have come across a serious problem: The SendMailCommand code currently changes the value of the "javax.net.ssl.trustStore" system property at run-time. This will cause problems when running multiple threads. Some other way will have to be found to handle this. Any suggestions?
not particularly beautiful, but can avoid side-effects on other takers of the "javax.net.ssl.trustStore" : Extend java.lang.InheritableThreadLocal and set the variable there. And obviously in the right place, also take it from there again...
(In reply to comment #23) > not particularly beautiful, but can avoid side-effects on other takers of the > "javax.net.ssl.trustStore" : > > Extend java.lang.InheritableThreadLocal and set the variable there. Useful to know. > And obviously in the right place, also take it from there again... Not sure that's possible. The code does not read the property so I assume it must be read by one of the libraries.
The clean approach for this is to have a SocketFactory implementation with built in TrustManager that will check the certificate based on the truststore. To understand it better look at the class TrustAllSSLSocketFactory written by Luca. We need to do the same idea but accepting only certificates that are n the truststore.
The SendMailCommand class also calls: Security.setProperty("ssl.SocketFactory.provider",...) which again will affect all threads. The code needs to be changed to set the socket factory for the specific sampler only. Similar code is used in the HttpSamplers, but I'm not sure those classes are directly usable here - they may well be http-specific. I think the best approach would be to commit the code with the current restrictions and then fix it, because most of it seems to be working.
Another issue - the code does not seem to need Bouncy Castle, so I removed the code which checks for it.
(In reply to comment #26) > The SendMailCommand class also calls: > > Security.setProperty("ssl.SocketFactory.provider",...) > > which again will affect all threads. Removed, as the prepareMessage() method already sets the appropriate property.
The cbUseLocalTrustStore tooltip currently just says "Please note:" I assume that there was supposed to be something else in the message? Any idea what it was?
Also, the trust settings are assymetrical. "Use SSL" can be used with "Trust All" and "Use Local", whereas StartTLS disables "Trust All" yet allows "Use Local". Surely if StartTLS can "Use Local" it should also be able to "Trust All"? Otherwise maybe it should not use either?
I don£t see any reason for this behaviour with the trustAll x Local keystore. If you look in the code of SendMailCommand, trustAllCerts is independent of start TLS. if (useStartTLS) { props.put("mail.smtp.starttls.enable", "true"); //props.put("mail.debug", "true"); } if (trustAllCerts && protocol.equalsIgnoreCase("smtps")) { props.setProperty("mail.smtps.socketFactory.class", TRUST_ALL_SOCKET_FACTORY); props.setProperty("mail.smtps.socketFactory.fallback", "false"); } To me this is a clear GUI bug.
Created attachment 25702 [details] Small patch to fix the described bug on TrustAllCerts. It also fixes the layout to completely fill the space.
OK, thanks for confirming. Applied to SVN: URL: http://svn.apache.org/viewvc?rev=960528&view=rev Log: Bug 45053 - SMTP-Sampler for JMeter + Fix trustAllCerts so it applies also to StartTLS option
Finally worked out how to use properties to control LocalTrustStore for both SSL and StartTLS. Requires JavaMail 1.4.2+ URL: http://svn.apache.org/viewvc?rev=960899&view=rev Log: New screenshot. SMTP sampler no longer thread-hostile Modified: jakarta/jmeter/trunk/docs/images/screenshots/smtp_sampler.png jakarta/jmeter/trunk/xdocs/images/screenshots/smtp_sampler.png jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml I think this is all complete now, so will close the bug. If there are any further issues, please raise a new issue.
Hello Sebb, Sorry to reopen this bug, but I attempted to run some test scripts with the code fresh from svn and I got this error. I tried to connect using local keystore and truts all certificates, both gave me the same error Thread Name: SigSvc_Pass_Mail 1-1 Sample Start: 2010-07-07 15:20:27 CEST Load time: 5151 Latency: 0 Size in bytes: -1 Sample Count: 1 Error Count: 1 Response code: 500 Response message: MessagingException: Server certificate not trusted - perhaps you have to restart JMeter! javax.mail.MessagingException: Can't send command to SMTP host; nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Response headers: SampleResult fields: ContentType: DataEncoding: null I used this script many times before to connect to the same server I am trying now and had no troubles.Any ideas of what could be happening?
The code now requires JavaMail 1.4.2+ (and comes with JavaMail 1.4.3). Previously JMeter nightly was using the Geronimo mail implementation - however that does not (yet) support all the mail properties now used by JMeter. Make sure that you delete the geronimo javamail and activation jars from the lib directory. Try also enabling debug - this should show if you are using Geronimo or the JavaMail from Oracle(Sun).
Thx a lot, it fixed my problem :) I will close the bug again.
OK, no problem, thanks for confirming it's OK. It was probably because I added a .ssl prefix to the socketFactory.class property. This was needed to support TrustAll with StartTLS. Without it, the mail implementation tried to use the SSL socketfactory to create the initial non-SSL socket - and failed. i.e. TrustAll needs mail.smtp.ssl.socketFactory.class, and will not work with mail.smtp.socketFactory.class For consistency, for SSL mode I also used the mail.smtps.ssl.socketFactory.class property. This requires Javamail 1.4.2+. I suppose I could have omitted the .ssl here as smtps always uses SSL sockets - in which case your test case would have worked with SSL+TrustAll on Geronimo. But Geronimo does not support the "mail.smtps[.ssl].socketFactory" property so it would not have worked with SSL+Local truststore.
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2116