Git Product home page Git Product logo

simple-java-mail's Issues

Proxy socket closed when connecting to authenticated proxy

I use proxy and after finish email was sending, however show exception like this.

Exception in thread "Thread-5" org.simplejavamail.mailer.internal.socks.common.SocksException: server crashed...
    at org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server.checkIoException(AnonymousSocks5Server.java:91)
    at org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server.run(AnonymousSocks5Server.java:76)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Socket closed
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
    at java.net.ServerSocket.implAccept(ServerSocket.java:545)
    at java.net.ServerSocket.accept(ServerSocket.java:513)
    at org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server.run(AnonymousSocks5Server.java:72)
    ... 1 more

Access to headers and flags...

One other thing which I spotted which aren't catered for by SimpleJavaMail but 
are by the Javamail API.

Headers
-------
Personally, I hate them, but clients are always asking if you can set the 
"important" flag on emails.  This is normally done by setting custom headers 
such as X-Priority and Importance.  To do this, javamail provides 
message.setHeader(String,String).  Would be good to be able to do this in 
simplejavamail

I'm now using simplejavamail "in anger" (although still in a testing phase) so 
I may well suggest some other enhancements as I find them.

As I said last time, great work...much easier than the javamail api.

Tom

Original issue reported on code.google.com by [email protected] on 18 Aug 2011 at 4:31

High CPU usage & geometrically increasing delay with increasing length of the recipient address

Measured with simple-java-mail-v2.1 and javax.mail-1.5.1

05-05-2015 16:53:48: Sending email: [email protected] -> [email protected] (3 attachments)
05-05-2015 16:53:48: These attachments were sent:
05-05-2015 16:53:48: Attachment 1 / 3 filename '108782_-_Sally-Ellen_Example.pdf', content type 'application/pdf'
05-05-2015 16:53:48: Attachment 2 / 3 filename '108782_Sally-Ellen_Example_108782_-_Ansioluetteloni.pdf', content type 'application/pdf'
05-05-2015 16:53:48: Attachment 3 / 3 filename '108782_Sally-Ellen_Example_108782_-_Hakemuskirje.pdf', content type 'application/pdf'
05-05-2015 16:55:57: DEBUG Mailer - starting mail session (host: null, port: null, username: null, authenticate: null, transport: SMTP_PLAIN)

05-05-2015 16:57:31: Sending email: [email protected] -> [email protected] (3 attachments)
05-05-2015 16:57:31: These attachments were sent:
05-05-2015 16:57:31: Attachment 1 / 3 filename '108782_-_Sally-Ellen_Example.pdf', content type 'application/pdf'
05-05-2015 16:57:31: Attachment 2 / 3 filename '108782_Sally-Ellen_Example_108782_-_Ansioluetteloni.pdf', content type 'application/pdf'
05-05-2015 16:57:31: Attachment 3 / 3 filename '108782_Sally-Ellen_Example_108782_-_Hakemuskirje.pdf', content type 'application/pdf'
05-05-2015 17:01:20: DEBUG Mailer - starting mail session (host: null, port: null, username: null, authenticate: null, transport: SMTP_PLAIN)

05-05-2015 17:16:47: Sending email: [email protected] -> [email protected] (3 attachments)
05-05-2015 17:16:47: These attachments were sent:
05-05-2015 17:16:47: Attachment 1 / 3 filename '108782_-_Sally-Ellen_Example.pdf', content type 'application/pdf'
05-05-2015 17:16:47: Attachment 2 / 3 filename '108782_Sally-Ellen_Example_108782_-_Ansioluetteloni.pdf', content type 'application/pdf'
05-05-2015 17:16:47: Attachment 3 / 3 filename '108782_Sally-Ellen_Example_108782_-_Hakemuskirje.pdf', content type 'application/pdf'
05-05-2015 17:25:24: DEBUG Mailer - starting mail session (host: null, port: null, username: null, authenticate: null, transport: SMTP_PLAIN)

Summary

Email address Addr. Length Start (hh:mm:ss) Finish (hh:mm:ss) Time taken Delta
[email protected] 48 16:53:48 16:55:57 0:02:09 n/a
[email protected] 49 16:57:31 17:01:20 0:03:49 0:01:40
[email protected] 50 17:16:47 17:25:24 0:08:37 0:04:48
[email protected] 51 DID NOT MEASURE -- This is the address that brought this problem to attention

I haven't verified with plain Java Mail if the problem persists.

Update SLF4J and JavaMail dependencies

The groupId for JavaMail changed, see this stackoverflow answer from the lead developer of JavaMail.
So the new maven coordinates right now are:

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.5.5</version>
</dependency>

The SLF4J dependency also got a bit stale, the most recent version right now is:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.13</version>
</dependency>

Thanks a lot for this library, it really makes my life easier. :)

Would be nice to add mock junit testing support

It would be nice to add a feature that performs all sorts of validations on the 
email, but stops short from actually delivering the email over the network.  
For unit testing purposes, etc.

Original issue reported on code.google.com by [email protected] on 12 Jul 2012 at 1:50

DKIM: bug on reading DNS TXT for DKIM long public key?

Hi I am newbie to GitHub.
SimpleJavaMail ported markenwerk/java-utils-mail-dkim, nice and thanks.
However I am not sure where I should post this issue, since markenwerk/java-utils-mail-dkim has no tab for "issue" and simple-java-mail is active here.
Anyway, while testing DKIM signing feature, I got the exception:

Obtaining the domain key for hubble.makedifferent.net.m failed
net.markenwerk.utils.mail.dkim.DkimSigningException: Obtaining the domain key for hubble.makedifferent.net.m failed
        at net.markenwerk.utils.mail.dkim.DkimSigner.sign(DkimSigner.java:442) ~[bin/:na]
        [...]
Caused by: java.io.IOException: net.markenwerk.utils.mail.dkim.DkimException: The public key MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB couldn't be read.
        at net.markenwerk.utils.mail.dkim.DkimSigningException.<init>(DkimSigningException.java:77) ~[bin/:na]
        ... 6 common frames omitted
Caused by: net.markenwerk.utils.mail.dkim.DkimException: The public key MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB couldn't be read.
        at net.markenwerk.utils.mail.dkim.DomainKey.getPublicKey(DomainKey.java:144) ~[bin/:na]
        [...]
Exception in thread "main" org.codemonkey.simplejavamail.MailException: Third party error: Obtaining the domain key for hubble.makedifferent.net.m failed
        at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:257)
        [...]
Caused by: net.markenwerk.utils.mail.dkim.DkimSigningException: Obtaining the domain key for hubble.makedifferent.net.m failed;
  nested exception is:
        java.io.IOException: net.markenwerk.utils.mail.dkim.DkimException: The public key MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB couldn't be read.
        at net.markenwerk.utils.mail.dkim.DkimSigner.sign(DkimSigner.java:442)
        [...]
Caused by: java.io.IOException: net.markenwerk.utils.mail.dkim.DkimException: The public key MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB couldn't be read.
        at net.markenwerk.utils.mail.dkim.DkimSigningException.<init>(DkimSigningException.java:77)
        ... 6 more
Caused by: net.markenwerk.utils.mail.dkim.DkimException: The public key MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB couldn't be read.
        at net.markenwerk.utils.mail.dkim.DomainKey.getPublicKey(DomainKey.java:144)
        [...]

Checking my DKIM public key:

> dig m._domainkey.hubble.makedifferent.net TXT
;; ANSWER SECTION:
m._domainkey.hubble.makedifferent.net. 13888 IN TXT "v=DKIM1\; k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" "CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB"

However in DomainKeyUtil.getValue(String) it retrieved as:

"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQw4AU7D/BKYINWOJJCjZ5OJJ7FzeuWU/B001/1yvxwtAvd/cuH3fRbWT0DUu49T+4igPwlCFnDkCkYvnY5otUPCGE8" CYOE6gx5FId0vX1X+CfEAcpqQZhTXr1kUUH6rbT6oiTAnGvkFhPP5PUICU6P9wZ0WJocsrkCVPYgXrQJQIDAQAB

I supposed it was due to multiple lines of TXT (DKIM) record:
https://help.directadmin.com/item.php?id=552

Therefore I made an override after String value = (String) txtRecord.get();

            String value = (String) txtRecord.get();
            if (null == value) {
                throw new DkimException("Value of RR " + recordName + " couldn't be retrieved");
            }
            value = bugfixMultipleLinesTxt(value);

    private static String bugfixMultipleLinesTxt(String value) {
        if (value.endsWith("\""))
            return value;

        if (value.startsWith("\"")) {
            value = value.substring(1);
        }
        int p = value.indexOf("\" ");
        while (p != -1) {
            value = value.substring(0, p) + value.substring(p + 2);
            p = value.indexOf("\" ");
        }
        return value;
    }

Then it works. Signature verified pass by Gmail Yahoo Microsoft.
Hardly believe that Attributes attributes = dnsContext.getAttributes(recordName, new String[] { "TXT" }); comes from javax.naming.directory.DirContext.getAttributes(String, String[])
Did I misunderstand anything?

Simple Java Mail from MimeMessage

I would need to handle files saved in .eml format, easily convertible into MimeMessage. It would be great to build SimpleMail from MimeMessage!
Thanks a lot!

Replace LOG4J with SLF4J + LOG4J

SLF4J is an interface which supports other logging frameworks and we can provide LOG4J as a default and let users override this choice for their own needs.

Minor enhancement

This is more a feature enhancement than a bug report.  The library seems 
excellent, but the one thing it doesn't support is the "reply to" option which 
JavaMail does.  Should just be a case of adding

1. a setReplyTo(String replyto) method to Email
2. a getReplyTo() method to Email
3. a check in Mailer to see whether a reply to is set and use it

This can be quite an important flag if using libraries in applications where 
you are sending on behalf of someone else.

Other than that, excellent work.

Original issue reported on code.google.com by [email protected] on 19 Jul 2011 at 9:01

Add access to the underlying javax.mail.Session properties

I had a case where the connection to the smtp server was hanging and never returning. It seems to be linked to the fact no value for the timeout parameters was is given when building the session. The parameters are mail.smtp.timeout and mail.smtp.connectiontimeout and there is currently no easy way to set these.

One option is to use the Mailer constructor with the Session argument, but then it fails on a NPE in logSession because the transportStrategy is not set. Also, a lot of the setup work has to be redone using this approach.

I think a better approach, would be to provide another arguments to the Mailer constructor, adding a Properties argument which would allow for full customisation of the session properties.

Need to document developer logging

Need to document developer logging options, system properties, 
logging.properties, etc.

I could find no information on this on your page.  If there, please provide a 
link...

Thanks,
Jeff

Original issue reported on code.google.com by [email protected] on 2 Nov 2012 at 12:07

Email attachments are not correctly encoded (the names)?

What steps will reproduce the problem?
1. Attach a file with åäö characters in them (like image)
2. Recieve the email and see åäö is now incorrectly encoded.
3.

What is the expected output? What do you see instead?
The file attached with correct name. The file attached with swedish characters 
garbled


What version of the product are you using? On what operating system?
2.1


Please provide any additional information below.
I did a quick google and mail attachmanet names needed to be encoded correctly. 
And I wonder if this is lacking.

Original issue reported on code.google.com by [email protected] on 23 Jul 2013 at 11:06

Email Validator

Version: 2.1

Issue: The Email validation goes into an infinite loop while trying to build the pattern matcher for the following email address: ewiuhdghiufduhdvjhbajbkerwukhgjhvxbhvbsejskuadukfhgskjebf@gmail.net (Obviously a random test case but, the behavior is surprising)

Trace: EmailValidationUtil line: 55

Version: 3.0 worked (this maybe due to the default behavior to skip the validator)

Add support for parallel batch processing

Make sending mails optionally async (threaded)

When sending multiple mails in quick succession, the current process is very slow because every mail being sent has to wait for the previous mail to finish.

There should be an option to do it asynchronously using new threads.

Restructure files

Now that simple-java-mail is growing a bit, the single package that holds everything is becoming a little messy. A simple util package and perhaps an email should be enough to separate the essentials from the rest.

Rename package to match domain simplejavamail.org

Now that Simple Java Mail has a proper home (simple-java-mail.org), we should rename the packages and maven groupId to match.

org.codemonkey.simplejavamail -> org.simplejavamail

This should be released as a major release (most likely v4.0.0).

Catastrophic backtracking in validation regexes

There are some email addresses that behave *very* poorly with the validation 
done in EmailValidationUtil.  I think it might be due to the nested quantifiers 
in the complex regexes there.  They literally take hours to finish the 
validation, using 100% CPU.

Is there any way to fix this, and barring that, can an option be added to skip 
validation?

To reproduce:
1. Try to send an email to an address like 
[email protected]
2. Wait for computer to explode

(Using java 1.6.0_31)

Original issue reported on code.google.com by [email protected] on 20 Apr 2012 at 10:13

Unicode in local part of email address fails

What steps will reproduce the problem?
1. Try to send email to å[email protected]

What is the expected output? What do you see instead?
Email should send according to http://tools.ietf.org/html/rfc6531

Instead i get: Get this error Could not send email. Inner error: Invalid TO 
address: org.codemonkey.simplejavamail.Email@60e6e627

What version of the product are you using? On what operating system?
I use 2.1 on windows

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 2 Sep 2014 at 9:47

Microsoft Exchange Server

Can we send mails using microsoft exchange server, if yes, please suggest a sample. thanks Aravind

Simple email sending doesn't work

What steps will reproduce the problem?
1. Just trying to implement the example that you provided in the wiki

What is the expected output?
Nothing just email has to be sent...

What do you see instead?
See here: http://pastebin.com/t58fWEpG

What version of the product are you using? On what operating system?
Latest

Please provide any additional information below.
Trying to send email with gmail. Added your libraries and code compiles OK. I'm 
using Eclipse on Xubuntu 11.10.

Original issue reported on code.google.com by [email protected] on 31 Jul 2012 at 3:28

Javadoc regarding default setting for email validation contradicting code, which is correct?

8370db1#commitcomment-16375443

The following javadoc and code show what the default email validation strictness is set to:

    /**
     * The default setting is not strictly 2822 compliant. For example, it does not include the {@link #ALLOW_DOMAIN_LITERALS} criteria, which results in
     * exclusions on single domains.
     * <p>
     * Included in the defaults are: <ul> <li>{@link #ALLOW_QUOTED_IDENTIFIERS}</li> <li>{@link #ALLOW_PARENS_IN_LOCALPART}</li> </ul>
     */
    public static final EnumSet<EmailAddressCriteria> DEFAULT = of(ALLOW_DOMAIN_LITERALS);

However, I'm not sure what actually should be the default. Do we even need a default? What is its purpose?

Initially I thought a more strict-than-RFC-compliant default would be needed to make sure main stream services and servers can handle the more mundane email strings, rather than the exotic strings the RFC would allow.

What should be the default?

NullPointerException in Mailer.sendMail(Email) when the Mailer(Session) constructor is used

When calling

    new org.codemonkey.simplejavamail.Mailer(mySession).sendMail(myEmail);

the following exception occurrs:

    Exception in thread "main" java.lang.NullPointerException
        at org.codemonkey.simplejavamail.Mailer.logSession(Mailer.java:260)
        at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:238)
        at MyClientCode

This is because Mailer.logSession(Session, TransportStrategy) tries to access 
members of the TransportStrategy, which was never initialized by the 
Mailer(Session) constructor.

Original issue reported on code.google.com by [email protected] on 19 Sep 2012 at 6:10

Add support for config files

Add support for config files, so that the SMTP and proxy server details can be configured there as well as a default subject, cc. bcc, from-address and reply-to-address.

Make the config path configurable, so that you can have different configuration files per environment.

bug on Email.signWithDomainKey(File, String, String)

Email.signWithDomainKey(File, String, String) new FileInputStream(File) and finally close(). ( too good coding habbit! )
This make the class member Email.dkimPrivateKeyInputStream unusable.
Later MimeMessageHelper.signMessageWithDKIM(MimeMessage, Email) new DkimSigner, the closed FileInputStream throws DataFetchException:

org.simplejavamail.mailer.internal.mailsender.MailSenderException: Error signing MimeMessage with DKIM
        at org.simplejavamail.mailer.internal.mailsender.MimeMessageHelper.signMessageWithDKIM(MimeMessageHelper.java:269) ~[simple-java-mail-4.1.1.jar:na]
        at org.simplejavamail.mailer.internal.mailsender.MimeMessageHelper.produceMimeMessage(MimeMessageHelper.java:82) ~[simple-java-mail-4.1.1.jar:na]
        at org.simplejavamail.mailer.internal.mailsender.MailSender.sendMailClosure(MailSender.java:219) ~[bin/:na]
        at org.simplejavamail.mailer.internal.mailsender.MailSender.send(MailSender.java:200) ~[bin/:na]
        at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:400) ~[bin/:na]
        at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:391) ~[bin/:na]
        at [...]
Caused by: net.markenwerk.utils.data.fetcher.DataFetchException: Fetch failed after 0 bytes have been copied successully.
        at net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher.createException(AbstractBufferedDataFetcher.java:98) ~[bin/:na]
        at net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher.doCopy(AbstractBufferedDataFetcher.java:90) ~[bin/:na]
        at net.markenwerk.utils.data.fetcher.AbstractDataFetcher.doCopy(AbstractDataFetcher.java:112) ~[bin/:na]
        at net.markenwerk.utils.data.fetcher.AbstractDataFetcher.copy(AbstractDataFetcher.java:106) ~[bin/:na]
        at net.markenwerk.utils.data.fetcher.AbstractDataFetcher.fetch(AbstractDataFetcher.java:73) ~[bin/:na]
        at net.markenwerk.utils.data.fetcher.AbstractDataFetcher.fetch(AbstractDataFetcher.java:61) ~[bin/:na]
        at net.markenwerk.utils.mail.dkim.DkimSigner.<init>(DkimSigner.java:220) ~[bin/:na]
        at org.simplejavamail.mailer.internal.mailsender.MimeMessageHelper.signMessageWithDKIM(MimeMessageHelper.java:260) ~[simple-java-mail-4.1.1.jar:na]
        ... 8 common frames omitted
Caused by: java.io.IOException: Stream Closed
        at java.io.FileInputStream.readBytes(Native Method) ~[na:1.8.0_91]
        at java.io.FileInputStream.read(FileInputStream.java:233) ~[na:1.8.0_91]
        at net.markenwerk.utils.data.fetcher.AbstractBufferedDataFetcher.doCopy(AbstractBufferedDataFetcher.java:79) ~[bin/:na]
        ... 14 common frames omitted

To fix, and taken I/O expense into account, I suggest to cache the byte[] into static Map<File,byte[]> inside Email.signWithDomainKey(File, String, String): (any security consideration on storing private key?)

class Email {
   static Map<File,byte[]> cachedDomainKeys = new HashMap<>();

public void signWithDomainKey(final File dkimPrivateKeyFile, final String signingDomain, final String selector) {
    [...]
    byte[] bytes = org.apache.commons.io.FileUtils.readFileToByteArray(dkimPrivateKeyFile);
    cachedDomainKeys.put(dkimPrivateKeyFile, bytes);
    dkimPrivateKeyInputStream = new ByteArrayInputStream(bytes);
    [...]

Thanks.

URLDataSource uses source data name

When adding at attachment from a URL source (e.g. a pdf on S3) the name of the attachment is not honored. Instead of the specified name, the file name of the resource is used. The workaround is simple - wrap using a named datasource. Something simple like the following worked for me,

private static final class NamedDataSource implements DataSource {
  private final DataSource delegate;
  private final String name;

  NamedDataSource(String name, DataSource delegate) {
    this.delegate = requireNonNull(delegate);
    this.name = requireNonNull(name);
  }

  @Override public String getName() {
    return name;
  }
  @Override public String getContentType() {
    return delegate.getContentType();
  }
  @Override public InputStream getInputStream() throws IOException {
    return delegate.getInputStream();
  }
  @Override public OutputStream getOutputStream() throws IOException {
    return delegate.getOutputStream();
  }
}

Possible in an Android Project?

Hi,
I'm trying to use this in my Android project but so far no luck. I was previously using "com.sun.mail:android-*:1.5.5" which worked but not so well with Gmail's SMTP and that's why I'm trying Simple Java Mail now.
During build I get these warnings:

`warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.DataHandler$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.SecuritySupport$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.SecuritySupport$2) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.SecuritySupport$3) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.SecuritySupport$4) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

warning: Ignoring InnerClasses attribute for an anonymous inner class (javax.activation.SecuritySupport$5) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.
`

The app runs fine until I get to the part of sending the actual mail:
java.lang.NoClassDefFoundError: javax.activation.DataHandler at javax.mail.internet.MimeBodyPart.setContent(MimeBodyPart.java:789) at org.codemonkey.simplejavamail.Mailer$MimeEmailMessageWrapper.<init>(Mailer.java:549) at org.codemonkey.simplejavamail.Mailer.produceMimeMessage(Mailer.java:335) at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:239) at xx.xx.xx.MailJob$1.doInBackground(MailJob.java:142)

and in that line I have new Mailer(host, port, user, pass, TransportStrategy.SMTP_TLS).sendMail(email);

Any input would be helpful.

Document thread-safety gurantees of Mailer

Is it recommended to create and share a single instance of Mailer between multiple threads after all configuration on it is done?

All the examples on the home page create a new Mailer instance and then (presumably) throw it away.

It just feels like one of those configure-once-and-use-it-everywhere objects like Jacksons ObjectMapper or a database connection pool. I assume that other developers will think the same, so it might be nice to have it spelled out somewhere (JavaDoc and/or Examples).

I haven't measured the overhead of creating a new Mailer for every E-Mail though, so it might as well be premature optimization.

SimpleMail not working with Gmail

I have a GMail account and am trying to use GMail to send emails for my simple app:

// Groovy pseudo-code
static void main(String[] args) {
    Email email = new Email()
    email.setFromAddress("Me Myself", "[email protected]");
    email.setSubject("hey!!");
    email.addRecipient("Some One", "[email protected]", RecipientType.TO);
    email.setText("We should meet up! ;)");

    Mailer mailer = new Mailer('smtp.gmail.com', 587, "[email protected]", "mygmail+password",
        TransportStrategy.SMTP_TLS)
    Properties props = new Properties()
    props.put('mail.smtp.auth', 'true')
    props.put('mail.smtp.starttls.enable', 'true')
    mailer.applyProperties(props)

    mailer.sendMail(email)
}

Produces:

<large stack trace omitted for brevity>
Caught: org.codemonkey.simplejavamail.MailException: Generic error: null
org.codemonkey.simplejavamail.MailException: Generic error: null
    at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:269)
    at org.codemonkey.simplejavamail.Mailer$sendMail$0.call(Unknown Source)
    at com.me.myapp.Driver.main(Driver.groovy:38)
Caused by: javax.mail.AuthenticationFailedException
    at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:261)
    ... 2 more

I've confirmed that my username/password are my correct gmail logins. Any thoughts here?

log4j configuration is being supplied with the library

Currently a configuration file for log4j2 is provided at:

./src/main/resources/log4j2.xml

This file is packaged up and bundled with the rest of the library. That means that any project that uses this application will have that log4j2.xml config file in their classpath.

Since most applications will want to provide their own logging implementations and configuration, it doesn't make sense for a library to be providing the log4j2.xml config file.

This problem is also present for an older version of simple-java-mail that included log4j.properties. This overrode the sandboxed log4j configuration that was provided by the system that ran my application if I was running from a debugger.

This stackoverflow post talks about this issue in the comments:

http://stackoverflow.com/a/5081386/622115

Thanks,

James

Add support for Proxy (HTTP, SOCKS, authenticated)

JavaMail only supports anonymous SOCKS proxy.

The only way to add this capability is by incorporating a SOCKS server into Simple Java Mail: it would be started when an email is being sent through Mailer.sendMail() and accepts the anonymous proxy connection from JavaMail on localhost and relays it to a proper proxy by also including a proxy client in Simple Java Mail which can connect to any proxy (HTTP, SOCKS, anonymous and authenticated).

So:

Mailer.sendMail() -> JavaMail Transport.send() (supports only anonymous SOCKS) -> Simple Java Mail temp proxy (anonymous SOCKS) -> Simple Java Mail proxy client -> the real proxy through which you want to go (HTTP, SOCKS, anonymous and authenticated)


But I don't want to balloon this library into the megabytes, because some open source proxy library included guava and netty and whatnot. Simple Java Mail is to remain a sleak library that includes everything in itself (by using the maven shade plugin).

Using .to() .cc() .bcc() from fluent builder API causes duplicated headers

I used the fluent builder API in order to add multiple recipients:

final Email email = new Email.Builder()
        .from(…)
        .subject(…)
        .text(…)
        .to("ONE", "[email protected]")
        .to("TWO", "[email protected]")
        .build();

The email object can be build without problems and gets send. The mail server then rejects the message telling the the header CC occurs more than one time. The recipients need to be a comma separated list value within only one CC header.

This bug also applies to the cc(…) and bcc(…) methods.

I rewrote my code using email.addRecipient(mailBoxName(mailbox), to, TO), then it works as expected.

It would be great to use the fluent API for that also and having a RFC compliant mail composed from it.

Internal code structure compromises integrity

Previous restructuring improved the logical folder structure, but package-technically compromised on integrity. That is to say, because of the way Java works with packages, some API had to be exposed to the public as the classes don't share the same folder anymore.

Case in point: the MessageException, which contains the message templates either has to be made public, or exceptions thrown by Email have to manage its own templates. This is messy.

We need a middle road here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.