title: Java send email, Getting error
body: <p>I wrote a program to send emails, but I don't know why I am getting an error.</p>
  
  <p>Pleas help me. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>import java.util.Properties;
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.AddressException;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage;
  
  
  
  public class EmailTest {
  
      static Properties mailServerProperties;
      static Session getMailSession;
      static MimeMessage generateMailMessage;
  
      public static void main(String args[]) throws AddressException, MessagingException {
          generateAndSendEmail();
          System.out.println("\n\n ===&gt; Your Java Program has just sent an Email successfully. Check your email..");
      }
  
      public static void generateAndSendEmail() throws AddressException, MessagingException {
  
  
          System.out.println("\n 1st ===&gt; setup Mail Server Properties..");
          mailServerProperties = System.getProperties();
          mailServerProperties.put("mail.smtps.host", "smtpout.secureserver.net");
          mailServerProperties.put("mail.smtp.auth", "true");
  
          System.out.println("Mail Server Properties have been setup successfully..");
  
  
          System.out.println("\n\n 2nd ===&gt; get Mail Session..");
          getMailSession = Session.getDefaultInstance(mailServerProperties, null);
          generateMailMessage = new MimeMessage(getMailSession);
          generateMailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("to@to.com"));
          generateMailMessage.addRecipient(Message.RecipientType.CC, new InternetAddress("cc@cc.com"));
          generateMailMessage.setSubject("TEST");
          String emailBody = "TEST BODY" + "&lt;br&gt;&lt;br&gt; DFKSDL, &lt;br&gt;JDSKJFDS";
          generateMailMessage.setContent(emailBody, "text/html");
          System.out.println("Mail Session has been created successfully..");
  
  
          System.out.println("\n\n 3rd ===&gt; Get Session and Send mail");
          Transport transport = getMailSession.getTransport("smtp");
          // Enter your correct gmail UserID and Password
          transport.connect("smtpout.secureserver.net", "username@user.com", "password");
          transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
          transport.close();
      }
  }
  </code></pre>
  
  <p>I am getting an error.  The username and password and everything are correct, but I am getting this error:</p>
  
  <pre><code> 1st ===&gt; setup Mail Server Properties..
  Mail Server Properties have been setup successfully..
  
  
   2nd ===&gt; get Mail Session..
  Mail Session has been created successfully..
  
  
   3rd ===&gt; Get Session and Send mail
  Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 550 &lt;username@partik-pc&gt; Sender Rejected - MAIL FROM must be a valid domain.
  ;
    nested exception is:
      com.sun.mail.smtp.SMTPSenderFailedException: 550 &lt;username@partik-pc&gt; Sender Rejected - MAIL FROM must be a valid domain.
  
      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 EmailTest.generateAndSendEmail(EmailTest.java:50)
      at EmailTest.main(EmailTest.java:20)
  Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 550 &lt;username@partik-pc&gt; Sender Rejected - MAIL FROM must be a valid domain.
  
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616)
      ... 3 more
  </code></pre>
  
  <p>I don't know why, username@partik-pc it puts my PC name after the username!! I don't know why.  Also, how can I attach a file? Please help me. Thanks in advance! </p>