Click here to Skip to main content
15,902,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir ,

below is my code in java ,this send mail without authenticate in ms exchange server,i want authenticate in ms exchange server ,

please help
Java
public void sendSSL(String to, String from1, String host1, String port1, String subject, String body, String fileAttachment1, String attachmentMimeType1, String username1, String password1)
    throws Exception
  {
    String username = username1; String password = password1;
    String from = from1; String host = host1; String smtpPort = port1;
    String attachmentMimeType = attachmentMimeType1; String fileAttachment = fileAttachment1;
    String[] tosendadd = new String[1];
    from = username;
    tosendadd[0] = to;
    Properties props = new Properties();
    props.put("mail.pop3.host", host);
    Session session = Session.getDefaultInstance(props);
    props.put("mail.smtp.user", username);
    props.put("mail.smtp.password", password);
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", smtpPort);

    int toCount = tosendadd.length;

    session = Session.getDefaultInstance(props, null);

    System.out.println("check");
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    InternetAddress[] address = new InternetAddress[toCount];
    for (int i = 0; i < toCount; i++)
      address[i] = new InternetAddress(tosendadd[i]);
    message.setRecipients(Message.RecipientType.TO, address);
    message.setSubject(subject);
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setDataHandler(new DataHandler(new HTMLDataSource(body)));
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    System.out.println("dhirendra1");
    if (fileAttachment != null)
    {
      messageBodyPart = new MimeBodyPart();
      FileDataSource fds = new FileDataSource(fileAttachment);
      messageBodyPart.setDataHandler(new DataHandler(fds));
      messageBodyPart.setFileName("abc.zip");
      multipart.addBodyPart(messageBodyPart);
    }
    System.out.println("dhirendra2");
    message.setContent(multipart);
    Transport.send(message);
    System.out.println("dhirendra3");
  }
Posted
Updated 21-Sep-15 23:22pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900