Hello,
whats the error in this code? I am not able to send mail. Getting error
"Cannot connect to SMTP host thru port 25"
If I send thru ASPMail, its working(SMTP)
This is my code...
// Sending e-mail
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
public final class EMailer
{
public static void main( String[] aArguments )
{
Properties p=System.getProperties();
p.put("mail.host","mx4.mail.yahoo.com");
p.put("mail.smtp.port","25");
p.put("mail.from","
[email protected]. sg");
EMailer emailer = new EMailer();
//the domains of these email addresses should be valid,
//or the example will fail:
emailer.sendEmail("
[email protected]. sg", "
[email protected]","Success", "Successfully sent from PVPSIT");
}
public void sendEmail( String aFromEmailAddr, String aToEmailAddr, String aSubject, String aBody )
{
Properties p=System.getProperties();
Session session = Session.getInstance(p, null);
session.setDebug(true);
MimeMessage message = new MimeMessage( session );
try
{
//the "from" address may be set in code, or set in the
//config file under "mail.from" ; here, the latter style is used
//message.setFrom( new InternetAddress(aFromEmailAddr) );
message.addRecipient(Message.RecipientType.TO, new InternetAddress(aToEmailAddr));
message.setSubject( aSubject );
message.setText( aBody );