• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java mail

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai friends,
I get the Following error while using Java Mail Program.

Program:

import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;

public class msgsend
{
public static void main(String[] argv)
{
new msgsend(argv);
}
public msgsend(String[] argv)
{
String to="[email protected]", subject ="Hai", from ="[email protected]", cc = null, bcc = null, url = null;
String mailhost = "mail.yahoo.com"; String mailer = "msgsend";
String protocol = "smtp", host = "mail.yahoo.com" , user = "archana", password = "null";
String record = null;
// name of folder in which to record mail
boolean debug = false;
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
int optind;
for (optind = 0; optind < argv.length;optind++)
{
if (argv[optind].equals("-T")) { protocol = argv[++optind]; }
else if (argv[optind].equals("-H")) { host = argv[++optind]; }
else if (argv[optind].equals("-U")) { user = argv[++optind]; }
else if (argv[optind].equals("-P")) { password = argv[++optind]; }
else if (argv[optind].equals("-M")) { mailhost = argv[++optind]; }
else if (argv[optind].equals("-f")) { record = argv[++optind]; }
else if (argv[optind].equals("-s")) { subject = argv[++optind]; }
else if (argv[optind].equals("-o")) { from = argv[++optind]; }
else if (argv[optind].equals("-c")) { cc = argv[++optind]; }
else if (argv[optind].equals("-b")) { bcc = argv[++optind]; }
else if (argv[optind].equals("-L")) { url = argv[++optind]; }
else if (argv[optind].equals("-d")) { debug = true; }
else if (argv[optind].equals("--")) { optind++; break; }
else if (argv[optind].startsWith("-")) {
System.out.println("Usage: msgsend [[-L store-url] | [-T prot] [-H host] [-U user][-P passwd]]");
System.out.println("\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
System.out.println("\t[-f record-mailbox] [-M transport-host] [-d] [address]");
System.exit(1); }
else
{ break; }
}
try
{ if (optind < argv.length)
{
// XXX - concatenate all remaining arguments
to = argv[optind];
System.out.println("To: " + to);
}
else
{ System.out.print("To: ");
System.out.flush();
to = in.readLine();
}
if (subject == null)
{
System.out.print("Subject: ");
System.out.flush();
subject = in.readLine();
}
else
{
System.out.println("Subject: " + subject);
}
Properties props = System.getProperties();
// XXX - could use Session.getTransport() and Transport.connect()
// XXX - assume we're using SMTP

if (mailhost != null) props.put("mail.smtp.host", mailhost);
Session session = Session.getInstance(props, null);
if (debug) session.setDebug(true);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc,false));
msg.setSubject(subject);
collect(in, msg);
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("\nMail was sent successfully.");
// Keep a copy, if requested.
if (record != null)
{
// Get a Store object
Store store = null;
if (url != null)
{
URLName urln = new URLName(url);
store = session.getStore(urln);
store.connect();
}
else
{
if (protocol != null)
store = session.getStore(protocol);
else
store = session.getStore();
// Connect
if (host != null || user != null || password != null)
store.connect(host,user, password);
else
store.connect();
}
// Get record Folder. Create if it does not exist.
Folder folder = store.getFolder(record);
if (folder == null)
{
System.err.println("Can't get record folder.");
System.exit(1);
}
if (!folder.exists())
folder.create(Folder.HOLDS_MESSAGES);
Message[] msgs = new Message[1];
msgs[0] = msg;
folder.appendMessages(msgs);
System.out.println("Mail was recorded successfully.");
}
}
catch (Exception e)
{ e.printStackTrace(); }
}
public void collect(BufferedReader in, Message msg)throws MessagingException, IOException
{
msg.setText("Hello");
}

}



Error:
To: [email protected]
Subject: Hai
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Unknown SMTP host: mail.yahoo.com;
nested exception is:
java.net.UnknownHostException: mail.yahoo.com
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at msgsend.<init>(msgsend.java:91)
at msgsend.main(msgsend.java:12)

Can Anyone tell me what the error is. ping www.mail.yahoo.com or telnet is also not working.

Archana
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"mail.yahoo.com" is an unknown SMTP host. If you weant to use JavaMail make sure you know the IP or URL address of the server you want to use. In the case of Yahoo you'll need to get in touch with them or search for some FAQs to get an actual server name you can use. I'd be very surprised if mail.yahoo.com was the actual host running the server - its more likely to be a URL which redirects to a specific server depending on load.
 
Archana Moorthy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul Sturrock ,
Thanks for your Reply. I worked the same code at my home PC where i have a direct internet connection And there establishes a connection to the yahoo server there. But in my college we have a LAN internet connection. Is there a problem due to it???

Archana S
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I also have a jsp which does not deliver mail to yahoo. In fact, i tried sending it to my indiatimes account but there also it failed. Then i gave up and stopped trying.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would imagine your college is using a proxy server somewhere. And that will most probably only support HTTP, so JavaMail can't communicate with the yahoo mail servers. Have a word with your network admin to check this. You might consider using your college's SMTP server if you can - since this won't have these problems.
[ August 24, 2004: Message edited by: Paul Sturrock ]
 
Archana Moorthy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul Sturrock,
I enquired the Admin and he says that the server supports SMTP. I think that the connection never goes to the server from java mail. I just looks in the local system and says the SMPT host is unrachable. What do you think?

Archana S
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't try to connect smtp.mail.yahoo.com with your user name/password provided?
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic