Hi i am trying to send email through java code i am i have installed cmail server for sending email but i am not able to send email how can i send email
here is my 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();}
}
}
when i run my program i am getting following Exception
com.sun.mail.smtp.SMTPSendFailedException: 550 [email protected] is not authorized.(WRONG SENDER MAILADDR)
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 550 [email protected] 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 [email protected] is not authorized.(WRONG SENDER MAILADDR)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616)
... 4 more
How can i achieve my output?
Thanks in advance