title: How to send email using javacode?
body: <p>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</p>
  
  <p>here is my code</p>
  
  <pre><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 = "shaktisharma27789@gmail.com";//change accordingly  
        String from = "admin@shakti-pc.com";
        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();}  
     }  
  } 
  </code></pre>
  
  <p>when i run my program i am getting following Exception</p>
  
  <pre><code>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
  </code></pre>
  
  <p>How can i achieve my output?</p>
  
  <p>Thanks in advance</p>