Comment envoyer des e-mail à l'aide de javacode?

Salut, je suis en train d'envoyer un email via le code java que je suis, j'ai installé cmail serveur pour l'envoi d'e-mail, mais je ne suis pas en mesure d'envoyer des e-mail comment puis-je envoyer un email

voici mon code

import java.util.*;  
import javax.mail.*;  
import javax.mail.internet.*;  
import javax.activation.*;  

public class SendEmail  
{  
 public static void main(String [] args){  
      String to = "[email protected]";//change accordingly  
      String from = "[email protected]";
      String host = "localhost";//or IP address  

     //Get the session object  
      Properties properties = System.getProperties();  
      properties.setProperty("mail.smtp.host", host);  
      Session session = Session.getDefaultInstance(properties);  

     //compose the message  
      try{  
         MimeMessage message = new MimeMessage(session);  
         message.setFrom(new InternetAddress(from));  
         message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
         message.setSubject("Ping");  
         message.setText("Hello, this is example of sending email  ");  

         //Send message  
         Transport.send(message);  
         System.out.println("message sent successfully....");  

      }catch (MessagingException mex) {mex.printStackTrace();}  
   }  
} 

quand je lance mon programme, j'obtiens Exception suivante

com.sun.mail.smtp.SMTPSendFailedException: 550 admin@shakti-pc.com is not authorized.(WRONG SENDER MAILADDR)
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 550 admin@shakti-pc.com is not authorized.(WRONG SENDER MAILADDR)

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at SendEmail.main(SendEmail.java:27)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 550 admin@shakti-pc.com is not authorized.(WRONG SENDER MAILADDR)

    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616)
    ... 4 more

Comment puis-je obtenir mon résultat?

Merci d'avance

InformationsquelleAutor user3493831 | 2014-04-25