• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Java Mail send message to Yahoo account

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am new to the Java mail API, and would like to use my local SMTP server to send mail to Yahoo account. I have tried varies options but none works. I do have a valid account in Yahoo, and tried to use the same account for both FROM and TO field. Also, i have configure the local SMTP server to relay mail.
The followings are the source code I got from one of the web discuss. but couldn't run it successfully
------------------------------------------------------
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class TestYahoo
{
// How to Run this program :
// java TestYahoo pop.mail.yahoo.com smtp.mail.yahoo.com <u'r yahoo username> <u'r yahoo password> <from mail address> <to mail address>

public static void main (String args[]) throws Exception
{
if (args.length != 6)
{
System.err.println("Usage : java TestYahoo <pop-Hostname> <smtp-Hostname> <username> <password> <fromAddress> <toAddress>");
return;
}
String pop3Host = args[0];
String smtpHost = args[1];
String username = args[2];
String password = args[3];
String from = args[4];
String to = args[5];
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, null);
Store store = session.getStore("pop3");
store.connect(pop3Host, username, password);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
Transport.send(message);
store.close();
}
}
--------------------------------------------------
C:\>java TestYahoo pop.mail.yahoo.com smtp.mail.yahoo.com Nancy_Johnson2002 [xx my password] [email protected] [email protected]
Exception in thread "main" javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at TestYahoo.main(TestYahoo.java:30)
Could anyone tell me what it fail...?
Help will be greatly appreciated...
Nancy
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Nancy Johnson,
yahoo doesn't allow to use their smtp or pop mail addresss in free of cost. so u will have to change the both of these two addresses.
n u can send mail by using the following code -
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class mailer
{
public static void main (String args[]) throws Exception
{
String smtpHost = "smtp.id.eth.net";
String from= "[email protected]";
String to= "[email protected]";
Properties props = System.getProperties();
props.put( "mail.smtp.host", smtpHost );
Session session = Session.getDefaultInstance( props, null );
session.setDebug( true );
MimeMessage message = new MimeMessage( session );
message.setFrom( new InternetAddress(from) );
message.addRecipient( Message.RecipientType.TO, new InternetAddress(to) );
message.setSubject( "subject" );
message.setContent( "message", "text/html" );
Transport.send( message );
}
}
If it doesn't work, then change the smtp address n run this program.
Bye
 
Nancy Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. I have decided to use the company's smtp server instead. It took me a while to figure out the smtp server name of my company since it's very hard to get a hold on mail server admin personnel. But i finally get it to work. However, i still have some problem on reading mail. The smtp server i am using allow me to send mail to any account. But when i try to read the mail, it doesn't seem to work. Why do i need to use pop3 as protocol? Does send and receive mail use different mail server? The server name i used for sending mail doesn't seem to be right for retrieving mails. I keep on getting connection refused error.
Thanks again for the help, and if you have any input on my question it will be greatly appreciated.
Nancy
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also getting an error:

javax.mail.MessagingException: * BYE Connection refused;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE Connection refused
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:569)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)


If you got your issue resolved please let me know as well.
It seems that the problem is security level on the MS Exchange server, and BTW< you need to use IMAP instead of POP3, since, MOST MS EXchange server, disable POP3 (these are internal corporate e-mail exchange servers)
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nancy and kamal.

You are getting the problem when smtp server refuses to connect.
You can try out one thing, just set connectiontimeout property of server.

props.put("mail.smtp.connectiontimeout", "21600000" );
props.put("mail.smtp.timeout", "21600000" );

It may help you out.
[ November 28, 2007: Message edited by: Vivek Mathur ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note that this thread is from 2003, so it's unlikely that the participants from way back then are still following it: DontWakeTheZombies

Secondly, there was no mention of Exchange, so I don't think that's relevant to this discussion.

Lastly, it's not a question a using POP or IMAP, it's a question of trying to use an SMTP server for POP3, which obviously won't work.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic