Hi, I am writing a program where I want the user to be able to e-mail me feedback, so I have downloaded javax.mail and I'm trying to send myself an e-mail to test it out. I have Yahoo Mail Plus. Below is my code, which I tweaked from one of the sample programs from javax.mail. I think the code after line 55 is just error display code.
package javamail;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class mymail
{
static String msgText = "This is a message body.\nHere's the second line.";
public static void main(String[] args)
{
String to = "bob@yahoo.com";
String from = "bob@yahoo.com";
String host = "plus.smtp.mail.yahoo.com";
boolean debug = true;
int port = 465;
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", Integer.toString(port));
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.ssl","true");
props.put("mail.smtps.auth", "true");
if (debug)
props.put("mail.debug", "true");
else
props.put("mail.debug", "false");
Authenticator auth = new Authenticator()
{
};
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
try
{
// create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress address = new InternetAddress(to);
msg.setRecipient(Message.RecipientType.TO, address);
msg.setSubject("JavaMail APIs Test");
msg.setSentDate(new Date());
// If the desired charset is known, you can use
// setText(text, charset)
msg.setText(msgText);
Transport.send(msg);
}
catch (MessagingException mex)
{
System.out.println("\n--Exception handling in msgsendsample.java");
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do
{
if (ex instanceof SendFailedException)
{
SendFailedException sfex = (SendFailedException)ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null)
{
System.out.println(" ** Invalid Addresses");
if (invalid != null)
{
for (int i = 0; i < invalid.length; i++)
System.out.println(" " + invalid[i]);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null)
{
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent != null)
{
for (int i = 0; i < validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null)
{
System.out.println(" ** ValidSent Addresses");
if (validSent != null)
{
for (int i = 0; i < validSent.length; i++)
System.out.println(" "+validSent[i]);
}
}
}
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
}
while (ex != null);
}
}
}
When I run this program I get this message:
530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
I thought that line 28 specified that I was connecting using "authorization". I notice that I have not specified a password anywhere. Is that the authentification problem this is referring to? I think I need to put something inside the brackets on line 36 and 37, but I'm not sure what. I also imagine I need to put something else into props also, but what? Thanks.