• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java mail urgent

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
}
}

------------------
 
reply
    Bookmark Topic Watch Topic
  • New Topic