• Post Reply Bookmark Topic Watch Topic
  • New Topic

java mail urgent

 
bhushan shelke
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am writing java mail code thr' java program . i have set all the classpatahs.it gives send failed exception giving errors
which indicates that it is not identifying smtp host.
my o.s. is win98.
I am sending this mail to yahoo account thr' my program.
pls tell me to what i should set "from" address.
is it necessary that i must have installed smtp host on my machine?
i am also attching code i am using pls help mei am new to java mail .my o.s. is win98
i have set all slasspaths appropriately. the code i have return gives errors
which indicates that it is not identifying smtp host.
I am sending this mail to yahoo account thr' my program.
pls tell me to what i should set "from" address.
i am also attching code i am using pls help me
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import java.util.Vector;
import java.io.*;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;
public class Mailer {
protected static Message prepareHeader(String smtp_host, String from,
String to, String subject)
throws IOException, AddressException,
MessagingException {
Properties props = new Properties();
props.put("smtp.host", smtp_host);
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
InternetAddress addr = new InternetAddress(to);
msg.addRecipients(Message.RecipientType.TO,
new InternetAddress[] {addr });
InternetAddress from_addr = new InternetAddress(from);
msg.setFrom(from_addr);
msg.setSubject(subject);
return msg;
}
public static void sendMail(String smtp_host, String from,String to, String subject, String message)throws IOException, AddressException,MessagingException
{
Message msg = prepareHeader(smtp_host, from, to, subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
public static void main(String args[])
{
try
{
Mailer m = new Mailer();
m.sendMail("mail.yahoo.com","bhushan_shelke@yahoo.com","vivekma_2000@yahoo.co m","mail","this is second mail");
}
catch(AddressException ade)
{
System.out.println(ade.getMessage());
}
catch(MessagingException mes)
{
System.out.println(mes.getMessage());
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
}

------------------
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!