sending email from Java in Windows
843830Jan 14 2005 — edited Jul 25 2007Just learning. All I have to do is to send a simple email to myself whenever my java application encounters some kind of misbehavior on client's site.
I made it thus:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class MySendMail {
static void Send() {
try {
InternetAddress toAddress = new InternetAddress("my address","my name");
InternetAddress fromAddress = new InternetAddress("my adress", "my name");
Properties props = new Properties();
props.put("mail.smtp.host", "smtpauth.earthlink.net");
Session mailsession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailsession);
msg.addRecipient(Message.RecipientType.TO, toAddress);
msg.setSubject("A Simple E-mail Message!");
msg.setFrom(fromAddress);
msg.setText("Sending this from java");
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Executing MySendMail.Send() gets this exception:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 550 Please configure your mail client to use authentication.
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1130)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:525)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at MySendMail.Send(S3i2SendMail.java:19)
May anybody please tell me the reason for the exception.
Many thanks,
Alex