SMTP Information for sending mail using JMail

When using JavaMail, set the SMTP host to:

localhost;

Below is a code example of sending email via Java application:

Message mailMsg;

<%@ page import="javax.mail.*,javax.mail.internet.*,java.util.*" %> <%
Message mailMsg;

Properties props = new java.util.Properties();
props.put("mail.smtp.host", "localhost");
Session s = Session.getDefaultInstance(props, null);
s.setDebug(false);

mailMsg = new MimeMessage(s);

InternetAddress fromAddress = new InternetAddress("support@netregistry.com.au");

String mto[] = new String[1];
mto[0] = "support@netregistry.com.au";

InternetAddress[] toAddress = new InternetAddress[mto.length];

for (int i = 0; i < mto.length; i++)
{
toAddress[i] = new InternetAddress(mto[i]);
}

mailMsg.setFrom(fromAddress);
mailMsg.setRecipients(Message.RecipientType.TO, toAddress);
mailMsg.setSubject("hi");

mailMsg.setSentDate(new java.util.Date());

StringBuffer sb = new StringBuffer().append("hello");

// set the body
mailMsg.setText(sb.toString());

// send the email
Transport.send(mailMsg);
%>

© 1997- 2008 Netregistry Pty Ltd