Invalid address problem. How can i Fix this.
843834Oct 6 2008 — edited Oct 6 2008Hi, basically I am trying to send an email using the mail-service.xml config file from jboss. Below is the configuration for my mail-service.xml .
<server>
<!-- ==================================================================== -->
<!-- Mail Connection Factory -->
<!-- ==================================================================== -->
<mbean code="org.jboss.mail.MailService"
name="jboss:service=Mail">
<attribute name="JNDIName">java:/Mail</attribute>
<attribute name="User">user@domain.com</attribute>
<attribute name="Password">password</attribute>
<attribute name="Configuration">
<!-- A test configuration -->
<configuration>
<!-- Change to your mail server prototocol -->
<property name="mail.store.protocol" value="pop3"/>
<property name="mail.transport.protocol" value="smtp"/>
<!-- Change to the user who will receive mail -->
<property name="mail.user" value="user@domain.com"/>
<!-- Change to the mail server -->
<property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
<!-- Change to the SMTP gateway server -->
<property name="mail.smtp.host" value="mail.daily.co.uk"/>
<!-- The mail server port -->
<property name="mail.smtp.port" value="587"/>
<!-- Change to the address mail will be from -->
<property name="mail.from" value="user@domain.com"/>
<!-- Enable debugging output from the javamail classes -->
<property name="mail.debug" value="true"/>
</configuration>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>
The problem is as follows. Everytime I try to send an email, I get the following error:
15:59:59,392 INFO [STDOUT] 250 Reset OK
15:59:59,392 INFO [STDOUT] javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 You must give your username and password to send mail through this service
I made sure that the email was in a valid format i.e recipient@domain.com . Below is the code I am using to send the email:
String serviceName = "java:/Mail";
Session session = null;
try {
InitialContext initialContext = new InitialContext();
session = (Session) initialContext.lookup(serviceName);
} catch (NamingException e) {
e.printStackTrace();
}
Message msg = new MimeMessage(session);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
Can someone point me in the right direction at what I am doing wrong. Every configuration details should b read from that mail-service.xml file. Why is it throwing an invalid address then a username and password error ?
Many thanks