Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support international email addresses #166

Closed
ghost opened this issue Sep 17, 2018 · 4 comments
Closed

Support international email addresses #166

ghost opened this issue Sep 17, 2018 · 4 comments
Milestone

Comments

@ghost
Copy link

ghost commented Sep 17, 2018

Background

Add support for internationalized email addresses. See:

Replicate

final EmailPopulatingBuilder builder = EmailBuilder.startingBlank();
builder.from("аджай@экзампл.рус");
// ...
final Email email = builder.buildEmail();
final Mailer mailer = MailerBuilder.buildMailer();
// ...
mailer.sendMail(email);

Also, try these:

  • French: François.Jacob@château.net
  • Chinese: 用户@例子.广告
  • Hindi: अजय@डाटा.भारत
  • Ukrainian: квіточка@пошта.укр
  • Greek: θσερ@εχαμπλε.ψομ
  • German: Dörte@Sörensen.example.com

Expected Results

Email is sent.

Actual Results

 org.simplejavamail.mailer.MailerException: Invalid FROM address: Email{
	id=null
	fromRecipient=Recipient{name='Александр Михайлович Лесной', address='аджай@экзампл.рус', type=null},
	replyToRecipient=null,
	bounceToRecipient=null,
	text='Hello, world! Voilà ! Le vieux château. À bientôt ! 一蓮托生',
	textHTML='',
	subject='Message subject line',
	recipients=[Recipient{name='null', address='username@localhost', type=To}]
}
	at org.simplejavamail.mailer.Mailer.validate(Mailer.java:276)
	at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:238)
	at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:230)
	at ca.bc.gov.educ.isd.notification.service.impl.EmailPayloadImpl.deliver(EmailPayloadImpl.java:171)
	at ca.bc.gov.educ.isd.notification.service.impl.EmailPayloadImpl.send(EmailPayloadImpl.java:96)
	at ca.bc.gov.educ.isd.notification.service.impl.EmailNotificationServiceBean.send(EmailNotificationServiceBean.java:25)
	at ca.bc.gov.educ.isd.notification.service.impl.EmailNotificationServiceBean.send(EmailNotificationServiceBean.java:9)
	at ca.bc.gov.educ.isd.notification.EmailNotificationServiceTest.send(EmailNotificationServiceTest.java:263)
	at ca.bc.gov.educ.isd.notification.EmailNotificationServiceTest.testEmailSend_OnRecipientBodySubjectI18N_ShouldDeliverMessageToRecipient(EmailNotificationServiceTest.java:69)

Workaround

Tried to disable validation as follows:

MailerBuilder.withEmailAddressCriteria(EnumSet.noneOf(EmailAddressCriteria.class))

This failed because the API does not permit setting the criteria to null, which is the entering condition for the validate method:

https://github.com/bbottema/simple-java-mail/blob/master/src/main/java/org/simplejavamail/mailer/Mailer.java#L287

Since MailerGenericBuilder assigns the email address criteria during construction and the methods to assign the validation enum set are tagged @Nonnull, it seems there is no way to avoid triggering validation (with or without an enum set).

This appears to be a minor oversight.

@bbottema
Copy link
Owner

Thanks for the bug report. This is a tough one, because the email validation library used doesn't support special symbols.

bbottema/email-rfc2822-validator#9

I'm not sure how to proceed here.

@ghost
Copy link
Author

ghost commented Sep 20, 2018

If there was a global control for validation of email addresses, as per #167, then this would not be an issue. I could use the Java Mail API directly to perform email address validation (as it has supported I18N since Java 1.6, I believe) and then continue using the SimpleJavaMail API for the remaining work.

See page 156 in https://javaee.github.io/javamail/docs/JavaMail-1.6.pdf for details.

@bbottema
Copy link
Owner

bbottema commented Sep 22, 2018

Nice, in al my Java Mail adventures I've not come across Java Mail's SAD! I'll study it carefully.

To get back to the issue, you can turn off email validation so only the injection checks remain:

currentMailerBuilder
   .clearEmailAddressCriteria()
   (..)

Perhaps I should make withEmailAddressCriteria() accept null value as well to avoid confusion, although the Javadoc does refer to clearEmailAddressCriteria (and it's in the features page).

@ghost
Copy link
Author

ghost commented Sep 26, 2018

Fixing issue #167 will make this issue no longer relevant. Closing.

@ghost ghost closed this as completed Sep 26, 2018
@bbottema bbottema added this to the 5.0.6 milestone Dec 28, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant