dcsimg
How can I send a Plain Text Mail useing JavaMail? I used a simple SendMail Program, but get an Exception related to smtphost.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jitendra_Kumar
Posted On:   Wednesday, August 23, 2006 07:37 AM

import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SendMail { public static void main (String args[]) throws Exception { if(args.length!=3) { System.out.println("Usage: SendMail SMTPHost ToAddr FromAddr"); System.exit(0); } String host = args[0]; String from = args[1]; String to = args[2]; // Get system properties Properties props = new Properties(); // Setup mail server props.put("mail.smtp.host", host); try { // Get session Session session = Session.getDefaultInstance(props, null); // Define    More>>
			
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class SendMail
{
public static void main (String args[]) throws Exception
{
if(args.length!=3)
{
System.out.println("Usage: SendMail SMTPHost ToAddr FromAddr");
System.exit(0);
}
String host = args[0];
String from = args[1];
String to = args[2];

// Get system properties
Properties props = new Properties();

// Setup mail server
props.put("mail.smtp.host", host);

try
{
// Get session
Session session = Session.getDefaultInstance(props, null);

// Define message
MimeMessage message = new MimeMessage(session);

// Set the from address
message.setFrom(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

// Set the subject
message.setSubject("Hello JavaMail");

// Set the content
message.setText("Welcome to JavaMail, This is a Test Mail by JavaMail Program.");

// Send message
Transport.send(message);

System.out.println("Message Sent");
}
catch(MessagingException me)
{
System.out.println("Exception occured: " + me);
}
}
}





I try this programm using following commands:


javac SendMail.java

java SendMail SMTP.localhost jitendra_jkr@yahoo.co.in jitendra_jkr@rediffmail.com



but i got this exception




javax.mail.MessagingException: Unknown SMTP host: SMTP.localhost;

nested exception is:

java.net.UnknownHostException: SMTP.localhost




Again, I try this programm using following commands,

here i gave the ip address through which my outlook is configured:


javac SendMail.java

java SendMail 192.168.3.16 jitendra_jkr@yahoo.co.in jitendra_jkr@rediffmail.com



but i got this exception


javax.mail.SendFailedException: Invalid Addresses;

nested exception is:

com.sun.mail.smtp.SMTPAddressFailedException: 554 : Relay access denied    <<Less

Re: How can I send a Plain Text Mail useing JavaMail? I used a simple SendMail Program, but get an Exception related to smtphost.

Posted By:   Anonymous  
Posted On:   Tuesday, August 29, 2006 06:06 AM

I think you should check your SMTP host address..because its working fine for me

Re: How can I send a Plain Text Mail useing JavaMail? I used a simple SendMail Program, but get an Exception related to smtphost.

Posted By:   WarnerJan_Veldhuis  
Posted On:   Wednesday, August 23, 2006 07:56 AM

Leave out the SMTP part of "SMTP.localhost". The server name for your server when installed locally is "localhost". Just that, nothing more.
About | Sitemap | Contact