[
https://issues.jboss.org/browse/WFLY-11818?page=com.atlassian.jira.plugin...
]
Yeray Borges commented on WFLY-11818:
-------------------------------------
[~mayerw01]
You must use Message.setFrom(), without arguments. As per Java Mail specification, it
retrieves the sender’s username from the local system and configure it for the message.
I've just used it with the Mail QS example and it worked fine in Wildfly, master
branch, Wildfly 16.0.0.Final and Widlfy-15.0.0.Final.
I used Message.setFrom(), without arguments \[1\] after configuring the 'from'
attribute \[2\], to avoid taking it from user.name environment variable. That means, your
Test2 case
'message.setFrom(new InternetAddress());', from my point of view, is invalid.
I'm not sure from where are you getting a NPE on your Test3 case, but, in my
environment it worked fine with WF15 as well.
Maybe the description of 'from' attribute of mail-session is a bit misleading, but
as per Java Mail specification, you have to call Message.setFrom() to retrieve the address
configured in the mail subsystem.
I can only suggest to do a double check; could you verify your email server accepts the
'from' address you are using and verify you are calling Message.setFrom() in your
code?
\[1\]
{code:java}
public void send() throws Exception {
Message message = new MimeMessage(mySession);
message.setFrom();
//This should not throw NPE
System.out.println(message.getFrom()[0].toString().equals("mytest(a)test.com"));
Address toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setContent(body, "text/plain");
Transport.send(message);
}
{code}
\[2\]
{code}
/subsystem=mail/mail-session=MyOtherMail:write-attribute(name=from,
value=mytest(a)test.com)
{code}
wildfly-16.0.0.Final: "From address" is no more used as
default from in email
-----------------------------------------------------------------------------
Key: WFLY-11818
URL:
https://issues.jboss.org/browse/WFLY-11818
Project: WildFly
Issue Type: Bug
Components: Mail
Affects Versions: 16.0.0.Final
Environment: mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: /apps/apache-maven-3.6.0
Java version: 11.0.2, vendor: Oracle Corporation, runtime: /usr/java/jdk-11.0.2
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "4.12.14-lp150.12.48-default", arch:
"amd64", family: "unix"
Reporter: Wolfgang Mayer
Assignee: Yeray Borges
Priority: Major
As mentioned in the Help (description) of 'Mail Session' configuration:
From: *From address that is used as default from, if not set when sending*
Apparently this is not the case anymore in wildfly-16.0.0.Final.
For example I made a test with quickstart-16.0/mail/.
When omitting the line
*message.setFrom(new InternetAddress(from));*
Sending mail fails with:
com.sun.mail.smtp.SMTPSendFailedException: 554-Transaction failed
554 Unauthorized sender address.
I have the same issue when replacing the line above with
message.setFrom(new InternetAddress());
I am pretty sure that this is working in wildfly-15
--
This message was sent by Atlassian Jira
(v7.12.1#712002)