glassfish smtp from name - java

We use a GlassFish server (JavaEE 7) with JavaMail.
Afaik, the official E-Mail RFC states that mail addresses may look something like this:
Tom Tester <tom.tester#test.com>
which would include a nicer representation than using only the email address. The Glassfish server is able to use this when configuring it on the admin console, clients like the GMail web client then display "Tom Tester" as sender. However, I'd like to specify the mail resource in the glassfish-resources.xml within our project, the configuration file doesn't allow < or >, because it's xml. I tried
<mail-resource
from="Tom Tester <tom.tester#test.com>"
...
and
<mail-resource
from="Tom Tester tom.tester#test.com"
...
, but these configurations won't work. Both approaches end up in sending only "tom.tester#test.com" as sender. I also didn't find any specification details from the GlassFish docs. Does somebody know if the desired behaviour is possible?

In case you want to explicitly set the personal name for the sender, you need to do it while creating the email message.
Let's say you have the session mailSession from the GlassFish Resource and you are creating a message mailMessage
Now you can set the from attribute of the message:
mailMessage.setFrom(new InternetAddress(mailSession.getProperty("mail.from"), "Tom Tester"));
Read more here.

Related

own java mail client & yandex smtp server - javax.mail.AuthenticationFailedException

evening,
i'm trying to do my own email client and then error came.
im using javax.mail library
i did try several methods for sending, most of them crash on sad places. anyway, one method i consider with potential is fine until end when message pops up:
m02 error-2: javax.mail.AuthenticationFailedException: 535 5.7.8 Error: authentication failed: Your message looks like spam. You need to use web for sending or prove you are not a robot using the following link http://ya.cc/[deleted] where [deleted] is originally few letters string.
i saw with gmail, you need to set something in settings to be able to use your own client, i expected this would be similar case but i couldn't find any settings about it in yandex mailbox settings.
another point, smtp address i have found at some forum so i presume it is possible to use own client
properties i set:
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.socketFactory.port", port_ssl);
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", port_ssl);
where
private String host = "smtp.yandex.com";
private String port_ssl = "465";
other code, im using classic way: Session for Authenticator, then Message and Transport.send. anyway, i think problem is with properties or mailbox settins? i just cant think of where.
question: how can i fix it so i can send an email with my client?
note: reason for using yandex is thanks to simple sign up since i dont have phone number and gmail requires one. if you know about other email service where own client should work & no need for phone that is also nice alternative answer
As an alternative answer, you could try the service https://protonmail.com, it should not require phone number and it can be reachable by SMTP clients using these settings https://mailsettings.co/protonmail-smtp-server-settings

Soap Connection timed out in Java client but not in SOAPUI

I created a soap client with wsimport and a given wsdl. I also used SoapUI to test the service. Using SoapUI I had no problem but when using my Java client I get
java.net.ConnectException: Connection timed out: connect
The default values I have in the requestContext are as follows
com.sun.xml.internal.ws.connect.timeout=100000
javax.xml.ws.service.endpoint.address=[fully qualified domain name endpoint]
com.sun.xml.internal.ws.request.timeout=100000
javax.xml.ws.soap.http.soapaction.use=null
com.sun.xml.internal.ws.client.ContentNegotiation=none
javax.xml.ws.soap.http.soapaction.uri=null
I've tried increasing the timeout but it still doesn't connect.
Has anyone else had a similar problem?
As you mentioned the problem is of proxy, it has been answered in below links.
How to use an HTTP proxy in java
Proxy settings in a java program
If you are using proxy with authentication then you have set authenticator along with the proxy. This is answered here.
Authenticated HTTP proxy with Java
EDIT:
As correctly mentioned by William Burnham, you have set to set the properties before calling them.
Morever, I recommend you to clear the property soon after getting response using System.clearProperty(key) as the property is set for complete instance of jvm till it is restarted and hence can cause problems for other outgoing connections.
The problem was I was behind a proxy. I did different tests and found that using a web browser (or SoapUI) I was able to access the resource but from the command line it wasn't working.
After much searching, it was a simple fix: either passing the property as a jvm argument or manually setting it in the code with System.setProperty("java.net.useSystemProxies", "true"). The JVM wasn't using the proxy on its own.
EDIT
As I used wsimport I have a jax-ws client. It's important that proxy settings be configured prior to instantiantion.
ANOTHER EDIT
If by chance you're having problems and you're using an application server to make the soap request through the proxy, you may have to specify java.net.useSystemProxies=true (or similar) in the server's configuration--for example catalina.properties if using tomcat.

Send mail to #hotmail.com/#live.com with JavaMail

I develop a application on android to send email. I want to use account MSN to send mail but it not send and error code on debug as below:
My configure on property are:
systemProperty.put("mail.smtp.starttls.enable","true");
systemProperty.put("mail.smtp.auth", "true");
systemProperty.setProperty("mail.host", "smtp.live.com");
systemProperty.put("mail.smtp.port", "587");
The password and email address are correct and i ever test with other host are work except MSN.
It looks like JavaMail isn't able to figure out your host name correctly, although I don't know why it would think "????" is your host name. Set the mail.smtp.localhost property to the correct host name for your machine. See the javadocs for the com.sun.mail.smtp package for details.
There seems nothing wrong with your configuration. 501 5.5.4 Invalid Address can be occuring because of the possible reasons below
The To email address is wrong in format (like check if it violates the possible combinations of email addresses. Eg., "My Name" - try simplifying it to myname#live.com and try
It might be bouncing email address
Check the library you use for sending this, how and what it allows

Kerberos SSO with Apache and Tomcat under JDK5

I'm new with this authentication through kerberos protocol so I tried to read a lot of howto on it but seems like I can't find any specifics with my constraints. Here is what I have :
An Active Directory Server on which users authenticate to log into their workstations
Each end user uses IE 7 to connect to my intranet application
An Apache server with load balancing
Some Tomcats servers acting as workers for the Apache server.
on each tomcat, I have 2 jakarta servlet running, users connect only on one servlet (further i will call it the servlet as if there is only one)
my tomcats need to run under jdk5. not jdk6 or jdk4. it's jdk5 period.
Now I want one to automatically get logged on my servlet. Basically I just need my servlet to retrieve the client's principal then I can manage the rest.
Based on what I understood, my client has a ticket, he ask the KDC for a special ticket for accessing the apache server, then he tries to connect to the Apache server. Based on his keytab, the apache server then decode the auth data and grant/refuse the access to specified resource.
Am I right? please guide me through this, I've been reading pages for 4 days and still no clue on which solution is the more appropriate. I tried mod_auth_kerberos for Apache but instead of grabbing the user's ticket he ask it like a basic auth. Apparently spgneo
Thanks
Ok I got this working :
Install Kerberos 5 + apache 2 + mod_auth_kerb.
On your AD, generate a keytab with only the principal you will use for Apache, I use HTTP/apache.mydom.com#MYDOM.COM
Put this keytab file on your apache server and make it readable only
by your Apache user.
Then edit your apache conf with these directive for your secure
location
apache.conf:
[…]
ServerName apache.mydom.com:80
[…]
LoadModule auth_kerb_module modules/mod_auth_kerb.so
[…]
<LocationMatch /secure)>
[… some other stuff …]
Order allow,deny
Allow from all
AuthType Kerberos
AuthName "Authentification requise"
KrbAuthRealms MYDOM.COM
#this allows user to be saved in the request
KrbSaveCredentials on
#this one force Negotiate AuthType instead of basic fallback
KrbMethodNegotiate on
#this trim the realm from username saved in the request (request.getRemoteUser() will give you "user" instead of "user#MYDOM.COM"
KrbLocalUserMapping on
KrbAuthoritative on
KrbVerifyKDC on
Krb5Keytab /install/binaries/httpd/apache.keytab
KrbServiceName HTTP
require valid-user
</LocationMatch>
And the one thing I almost failed to find on the web, you have to modify your tomcat server config (tomcat/conf/server.xml) :
<Connector [... AJP connector configuration ...] request.tomcatAuthentication="false"/>
This is really important because without it you tomcat won't retrieve any info from tomcat auth.
Don't forget too, DNS is really really really really important for a Kerberos install. If you have any issue try checking your DNS for all of your servers.

Transport not work for sending smtp email in java

I am using :
transport.connect(getHost(), getPort(), getUsername(), getPassword());
to send email, but it always gives me the following exception:
class com.sun.mail.smtp.SMTPAddressFailedException: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
But actually I have provided the username and password above, and the username and password is right as I tested in thunderbird, it can send email well.
So what's my problem ? Please point me the right direction. Thanks
When creating the javax.mail.Session, be sure the given properties contain:
props.put("mail.smtp.auth", "true");
http://www.oracle.com/technetwork/java/javamail/faq/index.html#smtpauth
I think that you need to talk to the administrators of the mail server to see what is going on. You might be using the wrong port for instance. Or there might be some local policy that you need to observe ...

Categories

Resources