Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaMail sending email using smtp in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


suresh anugandula
sending email using smtp in java
1 Answer(s)      2 years and 10 months ago
Posted in : JavaMail


Hi all,

I am trying to send and email to through my company mail server. Following is my code

package com.tbss;

import javax.mail.*; import javax.mail.internet.*;

import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*;

class tester {

public String toMD5(String string){

    byte[] defaultBytes = string.getBytes();
    try{
        MessageDigest algorithm = MessageDigest.getInstance("MD5");
        algorithm.reset();
        algorithm.update(defaultBytes);
        byte messageDigest[] = algorithm.digest();

        StringBuffer hexString = new StringBuffer();
        for (int i=0;i<messageDigest.length;i++) {
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        }
        String foo = messageDigest.toString();
        System.out.println("string "+string+" md5 version is "+hexString.toString());
        string=hexString+"";            
    }catch(NoSuchAlgorithmException nsae){
        nsae.printStackTrace();
    }
    return string;
}

public static void main(String args[]) { tester t=new tester(); String userName=t.toMD5("user"); String password=t.toMD5("password"); System.out.println("user name: "+userName); System.out.println("password: "+password); Properties props = new Properties(); props.put("mail.smtp.host" , "host"); props.put("mail.stmp.user" , userName);

  //To use TLS
 // props.put("mail.smtp.auth", "true"); 
  //props.put("mail.smtp.starttls.enable", "true");
  props.put("mail.smtp.password", password);
  //To use SSL
  props.put("mail.smtp.socketFactory.port", "465");
  props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  props.put("mail.smtp.startssl.enable", "true");
  props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.port", "25");

  SmtpAuthenticator authenticator=new SmtpAuthenticator();
  System.out.println("username: "+authenticator.getPasswordAuthentication().getUserName());
  Session session  = Session.getInstance( props , authenticator);
  session.setDebug(true);
  String to = "to@xxx.com";
  String from = "from@xxx.com";
  String subject = "Testing...";
  Message msg = new MimeMessage(session);
    try {
      msg.setFrom(new InternetAddress(from));
      msg.setRecipient(Message.RecipientType.TO , new InternetAddress(to));
      msg.setSubject(subject);
      msg.setText("Working fine..!");
      Transport transport = session.getTransport("smtp");
      transport.connect( "host" , 25 , userName , password );
      transport.send(msg);
      System.out.println("fine!!");
     }  catch(Exception exc) {
            System.out.println(exc);
        }

} static class SmtpAuthenticator extends Authenticator { public SmtpAuthenticator() {

        super();
    }

    @Override
    public PasswordAuthentication getPasswordAuthentication() {
        tester t=new tester();

     String username = t.toMD5("user");
     String password = t.toMD5("password");
        if ((username != null) && (username.length() > 0) && (password != null)
          && (password.length   () > 0)) {

            return new PasswordAuthentication(username, password);
        }

        return null;
    }
}

}

When i run this program i am getting following exception:

DEBUG: setDebug: JavaMail version 1.4.4 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "mail.tata-bss.com", port 25, isSSL false 220 IHGWTMEX07.SerWizSol.com Microsoft ESMTP MAIL Service ready at Wed, 21 Dec 2011 14:26:07 +0530 DEBUG SMTP: connected to host "host", port: 25

EHLO A5173423E.SerWizSol.com 250-IHGWTMEX07.SerWizSol.com Hello [10.64.170.164] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-X-ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250-XEXCH50 250 XRDST DEBUG SMTP: Found extension "SIZE", arg "" DEBUG SMTP: Found extension "PIPELINING", arg "" DEBUG SMTP: Found extension "DSN", arg "" DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg "" DEBUG SMTP: Found extension "AUTH", arg "NTLM" DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM" DEBUG SMTP: Found extension "8BITMIME", arg "" DEBUG SMTP: Found extension "BINARYMIME", arg "" DEBUG SMTP: Found extension "CHUNKING", arg "" DEBUG SMTP: Found extension "XEXCH50", arg "" DEBUG SMTP: Found extension "XRDST", arg "" DEBUG SMTP: Attempt to authenticate DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM DEBUG SMTP: mechanism LOGIN not supported by server DEBUG SMTP: mechanism PLAIN not supported by server DEBUG SMTP: mechanism DIGEST-MD5 not supported by server DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "mail.tata-bss.com", port 25, isSSL false 220 IHGWTMEX07.SerWizSol.com Microsoft ESMTP MAIL Service ready at Wed, 21 Dec 2011 14:26:08 +0530 DEBUG SMTP: connected to host "mail.tata-bss.com", port: 25

EHLO A5173423E.SerWizSol.com 250-IHGWTMEX07.SerWizSol.com Hello [10.64.170.164] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-X-ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250-XEXCH50 250 XRDST DEBUG SMTP: Found extension "SIZE", arg "" DEBUG SMTP: Found extension "PIPELINING", arg "" DEBUG SMTP: Found extension "DSN", arg "" DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg "" DEBUG SMTP: Found extension "AUTH", arg "NTLM" DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM" DEBUG SMTP: Found extension "8BITMIME", arg "" DEBUG SMTP: Found extension "BINARYMIME", arg "" DEBUG SMTP: Found extension "CHUNKING", arg "" DEBUG SMTP: Found extension "XEXCH50", arg "" DEBUG SMTP: Found extension "XRDST", arg "" DEBUG SMTP: Attempt to authenticate DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM DEBUG SMTP: mechanism LOGIN not supported by server DEBUG SMTP: mechanism PLAIN not supported by server DEBUG SMTP: mechanism DIGEST-MD5 not supported by server javax.mail.AuthenticationFailedException: 250-IHGWTMEX07.SerWizSol.com Hello [10.64.170.164] 250-SIZE 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-X-ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250-XEXCH50 250 XRDST

Please help me in resolving this problem.

Thanks, Suresh


Advertisement
View Answers

December 21, 2011 at 3:37 PM


Please visit the following link:

Java Mail API



Related Tutorials/Questions & Answers:
sending email using smtp in java
sending email using smtp in java  Hi all, I am trying to send and email to through my company mail server. Following is my code package com.tbss.....!"); Transport transport = session.getTransport("smtp
java code to send email using gmail smtp server
java code to send email using gmail smtp server  please send me the java code to send email using gmail smtp server. and how to send verification code
Advertisements
send mail using smtp in java
send mail using smtp in java  How to send mail using smtp in java?   Sending mail in JSP - SMTP
code for sending email using j2me
code for sending email using j2me  could someone tell me why when i try to compile this line using netbeans 7.1 Properties property... for sending a file attachment to gmail account
Email sending
Email sending  Hi sir, Am doing a project, in that i need to send email to multiple recipients at a same time using jsp so send me the code as soon as possible. Regards, Santhosh
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
Sending email without authentication
Sending email without authentication  Hi sir, Am doing a project in JSP, in that i want to send mail without any authentication of password so send.../mail/sending-an-email-in-jsp.shtml
sending automatic email - JavaMail
sending automatic email  Dear sir. In my project i need to send an automatic email to the clients when their accounts are going to expire in 30 days.i am using jsp,mysql and tomcat for my project.Expire information are stored
Sending an email in JSP
Sending an email in JSP       Sending an email in JSP In this section, you will learn how to send an email in jsp.   Following is a simple JSP page for sending
sending email code - JSP-Servlet
sending email code  How To Send Emails using jsp  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/mail/sending-an-email
Email sending in jsp - JSP-Servlet
Email sending in jsp  Hi, Im trying to send email from my jsp webserver.My webpage is running on Tomcat 5.0 server, and im using jsp coding.Now i've already tried a sample code from google, for sending email to my office 'smtp
Sending email with read and delivery requests
Sending email with read and delivery requests  Hi there, I am sending emails using JavaMail in Servlets on behalf of a customer from the website...   To read a mail, visit the following link: Java Read Mail
SMS sending questions using java - MobileApplications
using java language for sending SMS...SMS sending questions using java  am doing project sending SMS from... bulk SMS.am using mobile phone for sending SMS.is it possible sending bulk SMS
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
Sending and receiving xml message using Java Program
Sending and receiving xml message using Java Program  Hi Friends, I want to send and receive xml files between two java programs using wire format, could you suggest me the steps to be followed to acheive it or suggest some
Sending and receiving xml message using Java Program
Sending and receiving xml message using Java Program  Hi Friends, I want to send and receive xml files between two java programs using wire format, could you suggest me the steps to be followed to acheive it or suggest some
How to send and recieve email by using java mailserver
How to send and recieve email by using java mailserver  How to send and receive email by using java mail server?   Hi Friend, Please visit the following link: Java Mail Thanks
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
how to send sms on mobile and email using java code
how to send sms on mobile and email using java code  hi.... I am developing a project where I need to send a confirmation/updation msg on clients mobile and also an email on their particular email id....plz help me to find
Java Email
Java Email  I am making one java email applications using jsp-servlets. can you tell me that how can i recieve and send email dynamically in my application in UI... thanx.   Hi, Please read at Email From JSP &
sending mail using jsp
sending mail using jsp  please give me the detailed procedure and code for sending mail through jsp program   Please visit the following links: http://www.roseindia.net/ejb/introduction/j2eedemo.shtml http
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
SMTP server
SMTP server  Hi How to configure SMTP server.how can send mail using java script ex:I am developing registration page, user register after how can i send mail automatically thanks venu
Java Email
Java Email  i am writting a program to send emails using gmail smtp server. I had the following error: java.lang.ClassFormatError: Absent Code...) Exception in thread "main" Java Result: 1 BUILD SUCCESSFUL (total time: 6 seconds
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера
Sending data using bluetooth in android
Sending data using bluetooth in android  code to send data between two android mobile devices using bluetooth
Advertisements
 

 

 

DMCA.com