I'm working on a Java program (for fun) to send email through my IDE (JBuilder5). I'm having trouble getting my SMTP setup correctly. Could anyone help me out? The program compiles fine and I'm positive I have all of the packages added to the classpath it's just the damn SMTP setup. How should an SMTP be displayed? I thought I had it correct because it's what I entered to setup Outlook. Anyways, here's the code and thanks so much to any replies!
<code>
package email;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Sender {
protected String message_recip = "AMDPwred@mediaone.net";
protected String message_subject = "Test Email";
protected String message_cc = "";
protected String message_body = "This is just a test. ";
/* JavaMail session object */
protected Session session;
/* JavaMail message object */
protected Message mesg;
//Do the work, send the mail to the SMTP server.
public void doSend() {
Properties props = new Properties();
props.put("SMTP.VA.mediaone.net", "mailhost");
//Create the Session object
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
try {
//create a message
mesg = new MimeMessage(session);
//from address
mesg.setFrom(new InternetAddress("AMDPwred@mediaone.net"));
//to address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
//cc address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
//message subject
mesg.setSubject(message_subject);
//message body
mesg.setText(message_body);
//send the message
Transport.send(mesg);
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
//simple test case driver
public static void main(String[] av) {
Sender sm = new Sender();
sm.doSend();
}
}
</code>
<code>
package email;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Sender {
protected String message_recip = "AMDPwred@mediaone.net";
protected String message_subject = "Test Email";
protected String message_cc = "";
protected String message_body = "This is just a test. ";
/* JavaMail session object */
protected Session session;
/* JavaMail message object */
protected Message mesg;
//Do the work, send the mail to the SMTP server.
public void doSend() {
Properties props = new Properties();
props.put("SMTP.VA.mediaone.net", "mailhost");
//Create the Session object
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
try {
//create a message
mesg = new MimeMessage(session);
//from address
mesg.setFrom(new InternetAddress("AMDPwred@mediaone.net"));
//to address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
//cc address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
//message subject
mesg.setSubject(message_subject);
//message body
mesg.setText(message_body);
//send the message
Transport.send(mesg);
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
//simple test case driver
public static void main(String[] av) {
Sender sm = new Sender();
sm.doSend();
}
}
</code>