hi guys
i want your help i want to send email from private company email to yahoo or gmail company using java i will be thankful for any help

Recommended Answers

All 14 Replies

i see this page before and i downloaded the java mail but i cannot send an email from a yahoo to a yahoo but it work fine if i send email from gmail to a yahoo mail so my question if the from email that i want to send emails is for a private company email will it work????

If you have access to the SMTP server, then yes.

there something i donot know what is the smtp server?? and how i can know what smtp server? thank you for help

STMP is your outgoing mail server. If you don't know what it is, you will need to ask your network administrators about accessing it. Once you have that, you can follow the examples in the documentation.

hi look for this code it should work but it is not working

 String to = "ggggggggg@yahoo.com";
           Properties props;props = new Properties();
           props.put("mail.smtp.host", "smtp.yahoo.com");
           props.put("mail.smtp.auth", "true");
          props.setProperty( "mail.smtp.port", "587" );
           props.put("mail.smtp.starttls.enable", "true");

 Session session;
           session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
     protected javax.mail.PasswordAuthentication getPasswordAuthentication(){
        return new javax.mail.PasswordAuthentication("wwwww@yahoo.com", "ttttttttttt");
     }});
           try{
           MimeMessage message; 
                message   = new MimeMessage(session);
 message.setFrom(new InternetAddress("wwwww@yahoo.com"));//Sender Id.
 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
 message.setSubject("Hello!");
 message.setText("Testing from Java Application.......");

// send message.
 javax.mail.Transport.send(message);
 System.out.println("message sent successfully");}
           catch(MessagingException e){
             throw new RuntimeException();  
 } 

What the error/exception are you getting?

PS: this link was posted 4 years ago and seems to be similar to what you are trying to do.

i have no error but no message sent and the print statement doesnot apper

Is it a free Yahoo email account or a paid Yahoo Mail Plus account? Free accounts can't use SMTP.

thank you for help it is a free account so the code is true what about the port no?

I have no idea. That would depend on Yahoo's settings, but if it's a free account it doesn't matter anyway.

well, if I understood the question correctly, the recipient is supposed to be either yahoo or gmail, so whether or not it is free or paid for is not really important.

it is true but if i make the sender email is a yahoo email it will not send the message but if i send it from a gmail it will send the message but the sender email it is neither gmail or yahoo so my question is what part of the code i should change if the sending email is private company email??????

A private company email will have its own STMP propeties and accounts. You need to use those.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.