• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3043
  • Last Modified:

Java sendmail error

Hi Im using this code, but I get an error, I already check telnet and outlook in the same machine  and it works fine.
  public static void sendMail() {
    try{
      Properties properties = new Properties();
      properties.put("mail.smtp.host", MAILHOST); //set smtp server
      properties.put("mail.smtp.auth", AUTH); //use smtp authen properties.put("mail.transport.protocol", "smtp");
      properties.put("mail.smtp.port", "25");
      properties.put("mail.smtp.starttls.enable", "true");
      Session session = Session.getDefaultInstance(properties,
          new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(USER, PASSWORD);
        }
      });
      properties = session.getProperties();
      MimeMessage mimeMsg = new MimeMessage(session);
      mimeMsg.setFrom(new InternetAddress(MAILFROM));
      mimeMsg.setRecipients(Message.RecipientType.TO, MAILTO);

      mimeMsg.setSubject("Error sistema distribuido: " + MAILHOST);
      MimeBodyPart part = new MimeBodyPart();
      part.setText(CONTENIDO == null ? "" : CONTENIDO.trim());
      part.setContent(CONTENIDO, "text/plain;charset=UTF-8");
      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(part);
      mimeMsg.setContent(multipart);
      mimeMsg.setSentDate(new Date());
      Transport.send(mimeMsg);
    }
    catch(Exception e){
      System.out.println(e.getMessage());
    }
0
aaguia
Asked:
aaguia
  • 12
  • 7
  • 7
1 Solution
 
mrcoffee365Commented:
Please post the exception you're getting, with the stack trace (not just the message).
0
 
mohammedfCommented:
i didn't know what is happening ,, and u didn't paste ur error message
here is working example of sending email using jsp and java

package myClasses;
 
public class EMailBean {
 
	private String smtp,username,password,from,to,cc,bcc,subject,body,attachments;
	
						/*setter*/
	public void setSmtp(String str){this.smtp=str;}
	public void setUsername(String str){this.username=str;}
	public void setPassword(String str){this.password=str;}
	public void setFrom(String str){this.from=str;}
	public void setTo(String str){this.to=str;}
	public void setCc(String str){this.cc=str;}
	public void setBcc(String str){this.bcc=str;}
	public void setSubject(String str){this.subject=str;}
	public void setBody(String str){this.body=str;}
	public void setAttachments(String str){this.attachments=str;}
	
		
						/*getter*/
	public String getSmtp( ){return this.smtp;}
	public String getUsername( ){return this.username;}
	public String getPassword( ){return this.password;}
	public String getFrom( ){return this.from;}
	public String getTo( ){return this.to;}
	public String getCc( ){return this.cc;}
	public String getBcc( ){return this.bcc;}
	public String getSubject( ){return this.subject;}
	public String getBody( ){return this.body;}
    public String getAttachments( ){return this.attachments;}
 
}
//////////////////////////////////////////////
 
package myClasses;
import java.util.Properties;
import java.util.Date;
 
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.*;
 
 
public class SendMailBean {
 
    
 
  public String send(EMailBean mail) {
  	
	
    String result = "<BR><BR><BR><BR><BR><BR><BR>";
     
    Properties props = System.getProperties();
    props.put("mail.smtp.host", mail.getSmtp());
    props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");
	
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(true); 
 
    try {
      
                        MimeMessage msg = new MimeMessage(session);
                        msg.setFrom(new InternetAddress(mail.getFrom()));
                        msg.addRecipient(Message.RecipientType.TO,new InternetAddress(mail.getTo()));
                        msg.setSubject(mail.getSubject());
                        
 
                        // Create the message part
                        BodyPart messageBodyPart = new MimeBodyPart();
 
                        // Fill the message
                        messageBodyPart.setText(mail.getBody());
 
                        Multipart multipart = new MimeMultipart();
                        multipart.addBodyPart(messageBodyPart);
 
                        // Part two is attachment
                        messageBodyPart = new MimeBodyPart();
                        DataSource source = new FileDataSource(mail.getAttachments());
                        messageBodyPart.setDataHandler(new DataHandler(source));
                        messageBodyPart.setFileName(source.getName());
                        multipart.addBodyPart(messageBodyPart);
 
                        msg.setContent(multipart);
                        msg.setSentDate(new Date());
 
           
      
     Transport t = session.getTransport("smtp");
    try {
        t.connect(mail.getUsername(), mail.getPassword());
        t.sendMessage(msg, msg.getAllRecipients());
    } finally {
        t.close();
    }
 
      
      
      
      
      result = result + "<FONT SIZE=4 COLOR=\"blue\"><B>Success!</B>"+"<FONT SIZE=4 COLOR=\"black\"> "+"<HR><FONT color=green><B>Mail was successfully sent to </B></FONT>: "+mail.getTo()+"<BR>";
                 
      if (!("".equals(mail.getCc())))
        result = result +"<FONT color=green><B>CCed To </B></FONT>: "+mail.getCc()+"<BR>";
      if (!("".equals(mail.getBcc())))
        result = result +"<FONT color=green><B>BCCed To </B></FONT>: "+mail.getBcc() ;
 
      result = result+"<BR><HR>";
    } catch (MessagingException mex) {
        result = result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+"<FONT SIZE=3 COLOR=\"black\">"+mex.toString()+"<BR><HR>";
    } catch (Exception e) {
 
 
        result = result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> "+"<FONT SIZE=3 COLOR=\"black\">"+e.toString()+"<BR><HR>";
 
        e.printStackTrace();
    }
    finally {
      return result;
    }
  } 
 
} 
///////////////////////////////////////////////
index.html
//////////////////////////////////////////////
<HTML>
<HEAD>
<TITLE>Sending Mail using Java Mail API</TITLE>
</HEAD>
 
 <SCRIPT LANGUAGE="JavaScript1.1">
    function submission1() {
      if(document.forms[0].from.value =="" ||
         document.forms[0].to.value =="" ||
         document.forms[0].smtp.value =="") {
        alert("Host, From and To fields are mandatory.");
        return;
      }
 
      document.forms[0].action = "SendMail.jsp";
      document.forms[0].submit();
    }
  </SCRIPT>
  <CENTER>
   <TABLE BGCOLOR=black WIDTH=100% CELLPADDING="1">
    <TR><TD bgcolor="#FFFFFF">
 
     <CENTER><B><FONT SIZE=3>Send Mail Page</TD></TR>
   </TABLE>
   <TABLE BORDER=0 >
    <TR>
    <TD>
      <FORM METHOD=POST action="SendMail.jsp">
      <TABLE BORDER=0 CELLPADDING=4>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>Mail Server Host</b></TD>
 
              <TD ALIGN=LEFT width="298">
                
                <INPUT TYPE="text" NAME="smtp" SIZE=20 value="smtp.gmail.com" >
          </TD>
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124" height="31"><b>Username</b></TD>
 
              <TD ALIGN=LEFT width="298" height="31">
                
                <INPUT TYPE="text" NAME="username" SIZE=20 ></TD>
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>Password</b></TD>
 
              <TD ALIGN=LEFT width="298">
                
                <INPUT TYPE="password" NAME="password" SIZE=20 ></TD>
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>From</b></TD>
              <TD ALIGN=LEFT width="298">
                <INPUT SIZE=20 MAXLENGTH=60 NAME="from">
          </TD>
 
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>To</b></TD>
              <TD ALIGN=LEFT width="298">
                <INPUT SIZE=60 MAXLENGTH=200 NAME="to"></TD>
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>CC</b></TD>
              <TD ALIGN=LEFT width="298">
                <INPUT SIZE=60 MAXLENGTH=200 NAME="cc"></TD>
 
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>BCC</b></TD>
              <TD ALIGN=LEFT width="298">
                <INPUT SIZE=60 MAXLENGTH=200 NAME="bcc"></TD>
        </TR>
        <TR>
              <TD ALIGN=RIGHT width="124"><b>Attachments</b></TD>
              <TD ALIGN=LEFT width="298">
                <input type="file" name="attachments" size="20"></TD>
        </TR>
 
        <TR>
              <TD ALIGN=RIGHT width="124"><b>Subject</b></TD>
              <TD ALIGN=LEFT width="298">
                <INPUT SIZE=60 MAXLENGTH=100 NAME="subject" value="hi"></TD>
        </TR>
 
      </TABLE>
          <p align="left">
          <b>Message</b><br>
      <TEXTAREA NAME="body" ROWS=7 COLS=66 SIZE=2000 WRAP=HARD>hihihihihihihihihihihihihihi</TEXTAREA>
      </p>
		<CENTER>
      <INPUT TYPE=BUTTON VALUE=" Send " onClick="submission1();">  
      <br>
      </CENTER>
      </FORM>
    </TD>
    </TR>
  </TABLE>
  </CENTER>
  </BODY>
 
</HTML>
//////////////////////////////////////////////
SendMail.jsp
//////////////////////////////////////////////
<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<HTML>
  <HEAD>
 
  <TITLE>Send Email</TITLE>
  </HEAD>
  <CENTER>
  <BR>
 
  <%@ page import="myClasses.*"%>
  <jsp:useBean id="sendMail" class="myClasses.SendMailBean" scope="page" />
  <jsp:useBean id="email" class="myClasses.EMailBean" scope="page" />
  <jsp:setProperty name="email" property="*"/>
 
  
  <%
    String result=sendMail.send(email);
  %>
  
 <%=result%>
    <FONT SIZE=3 COLOR="blue">
  <A HREF="index.jsp">Compose Mail</A>
  </CENTER>
  </BODY>
</HTML>

Open in new window

0
 
aaguiaAuthor Commented:
Hi sorry that I miss such importa part, the error that Im getting is 530 5.7.0 No AUTH
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mohammedfCommented:
this means that the username and password u provide are incorrect
try to make sure that u provide a correct user and password
0
 
aaguiaAuthor Commented:
The user and password are correct I already check this using outlook in the same machine.
0
 
aaguiaAuthor Commented:
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "XXX.XX.XX.co", port 25, isSSL false
220 *****************************************************************0 *******************2**200***
DEBUG SMTP: connected to host "XXX.XXX.XXX.co", port: 25

EHLO XXXX
500 5.5.1 Unknown command "XXXX XXXX" specified
HELO XXXX
250 xxx.xx.xx.co OK, [190.156.158.86].
DEBUG SMTP: use8bit false
MAIL FROM:<xxx@xxx.xx.co>
530 5.7.0 No AUTH command has been given.
DEBUG SMTP: got response code 530, with response: 530 5.7.0 No AUTH command has been given.

RSET
250 2.5.0 Ok.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 No AUTH command has been given.

      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
      at javax.mail.Transport.send0(Transport.java:189)
      at javax.mail.Transport.send(Transport.java:118)
      at siac.sd.servidor.servicios.EnviarMail.sendMail(EnviarMail.java:73)
      at siac.sd.servidor.servicios.PruebaMail.main(PruebaMail.java:27)
QUIT
221 2.3.0 Bye received. Goodbye.
Error en el envio del mail: 530 5.7.0 No AUTH command has been given.
0
 
aaguiaAuthor Commented:
No luck!!!
0
 
mohammedfCommented:
can u try the code i posted ?
0
 
aaguiaAuthor Commented:
I simplified the code that you posted, because im using for testing a main method. The code is almost the same that I have. Here's the code. I remove the attach part because I dont have any attachment.

    String result = "";

    Properties props = System.getProperties();
    props.put("mail.smtp.host", "XXX.XX.XXco");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");

    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(true);

    try {

      MimeMessage msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("XXX@XX.XX.co"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress("XX.XX@gmail.com"));
      msg.setSubject("Test");

      // Create the message part
      BodyPart messageBodyPart = new MimeBodyPart();

      // Fill the message
      messageBodyPart.setText("Hihihihihihihi");

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);
      msg.setContent(multipart);
      msg.setSentDate(new Date());

      Transport t = session.getTransport("smtp");
      try {
        t.connect("XXXX", "XXX");
        t.sendMessage(msg, msg.getAllRecipients());
      }
      finally {
        t.close();
      }

      result = result + "<FONT SIZE=4 COLOR=\"blue\"><B>Success!</B>" + "<FONT SIZE=4 COLOR=\"black\"> " +
          "<HR><FONT color=green><B>Mail was successfully sent to </B></FONT>: " + "alan.aguia@gmail.com" + "<BR>";

      result = result + "<BR><HR>";
    }
    catch (MessagingException mex) {
      result = result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> " + "<FONT SIZE=3 COLOR=\"black\">" +
          mex.toString() + "<BR><HR>";
    }
    catch (Exception e) {

      result = result + "<FONT SIZE=4 COLOR=\"blue\"> <B>Error : </B><BR><HR> " + "<FONT SIZE=3 COLOR=\"black\">" +
          e.toString() + "<BR><HR>";

      e.printStackTrace();
    }

Anayway the result was the same

DEBUG: setDebug: JavaMail version 1.4.1
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 "unmtaout.unal.edu.co", port 25, isSSL false
220 *****************************************************************0 *******************2**200***
DEBUG SMTP: connected to host "XXXX.XX.XX.co", port: 25

EHLO XX
500 5.5.1 Unknown command "XXXX XXX" specified
HELO XXX
250 XXX.XX.XX.co OK, [190.156.158.86].
DEBUG SMTP: use8bit false
MAIL FROM:<XXX@XX.XX.co>
530 5.7.0 No AUTH command has been given.
DEBUG SMTP: got response code 530, with response: 530 5.7.0 No AUTH command has been given.

RSET
250 2.5.0 Ok.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 No AUTH command has been given.

      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
      at siac.sd.servidor.servicios.smtpsend.main(smtpsend.java:115)
QUIT
221 2.3.0 Bye received. Goodbye.
0
 
mohammedfCommented:
i think that the problem is in the SMTP server u use ,,, not in the code
0
 
aaguiaAuthor Commented:
But I can send messeges using outlook in the same machine.
0
 
mohammedfCommented:
may be u need a permission from SMTP admin ... some SMTP require this kind of permitions
0
 
mrcoffee365Commented:
The likely problem is that the code that mohammedf gave you does not include setting the email username and password.  In Outlook, you've probably saved your username and password.
0
 
aaguiaAuthor Commented:
But in my code I consider email, username and password and it doesnt work anyway.
0
 
mrcoffee365Commented:
Yes, you had other problems in your code.

This is what I did to make the code that mohammedf gave you work for a password protected mail account:

* Add an authenticator (yours didn't work -- I didn't track down why, I just used one that has worked for me as a demonstration in the past.  See class code below.)
* Change the body of your code to use the authenticator, use the transport differently, etc.:

      Properties properties = new Properties();
      javax.mail.Authenticator authenticator = new DefaultAuthenticator(mailuser,mailpassword);
      properties.put("mail.smtp.host", mailHost);
      properties.put("mail.smtp.auth", "true");
      properties.put("mail.smtp.port", "25");
      properties.put("mail.smtp.starttls.enable", "true");

      Session session = Session.getInstance(properties, authenticator);
      session.setDebug(true);
      MimeMessage mimeMsg = new MimeMessage(session);
      mimeMsg.setFrom(new InternetAddress(mailFrom));
      mimeMsg.setRecipients(Message.RecipientType.TO, mailTo);

      mimeMsg.setSubject(mailSubject);
      MimeBodyPart part = new MimeBodyPart();
      part.setText(mailContent == null ? "" : mailContent.trim());
      part.setContent(mailContent, "text/plain;charset=UTF-8");
      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(part);
      mimeMsg.setContent(multipart);
      mimeMsg.setSentDate(new Date());
      Transport.send(mimeMsg);

DefaultAuthenticator.java -- class for simple authenticator
---------------------------------------------------------------
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
 
/**
 * This is a very simple authentication object that can be used for any
 * transport needing basic userName and password type authentication.
 *
 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 * @version $Id: DefaultAuthenticator.java,v 1.3 2004/02/19 22:38:07 scolebourne Exp $
 */
public class DefaultAuthenticator extends Authenticator
{
    /** Stores the login information for authentication */
    private PasswordAuthentication authentication;
 
    /**
     * Default constructor
     *
     * @param userName user name to use when authentication is requested
     * @param password password to use when authentication is requested
     */
    public DefaultAuthenticator(String userName, String password)
    {
        this.authentication = new PasswordAuthentication(
                userName, password );
    }
 
    /**
     * Gets the authentication object that will be used to login to the mail
     * server.
     *
     * @return A <code>PasswordAuthentication</code> object containing the
     *         login information.
     */
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return this.authentication;
    }
}

Open in new window

0
 
aaguiaAuthor Commented:
I had the same problem

DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "XXXX.XX.XX.co", port 25, isSSL false
220 *****************************************************************0 *******************2**200***
DEBUG SMTP: connected to host "XXX.XXX.XXX.co", port: 25

EHLO XXX
500 5.5.1 Unknown command "XXXX XXX" specified
HELO XXX
250 unportal.unal.edu.co OK, [190.156.171.164].
DEBUG SMTP: use8bit false
MAIL FROM:<XXX@XXX.XX.co>
530 5.7.0 No AUTH command has been given.
DEBUG SMTP: got response code 530, with response: 530 5.7.0 No AUTH command has been given.

RSET
250 2.5.0 Ok.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 No AUTH command has been given.

      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
      at javax.mail.Transport.send0(Transport.java:189)
      at javax.mail.Transport.send(Transport.java:118)
      at siac.sd.servidor.servicios.EnviarMail.sendMailOtro(EnviarMail.java:73)
      at siac.sd.cliente.main.PruebaMail.main(PruebaMail.java:28)
QUIT
221 2.3.0 Bye received. Goodbye.
0
 
mrcoffee365Commented:
We need to see the code.  It's good to post the full error messages, as you have, but since the code works for me with an authenticated mail server, my hope is that we'll be able to find the problem in your code.
0
 
aaguiaAuthor Commented:
The code is the same that you post it
0
 
aaguiaAuthor Commented:
Anyway the code
DefaultAuthenticator.java

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

/**
 * This is a very simple authentication object that can be used for any
 * transport needing basic userName and password type authentication.
 *
 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 * @version $Id: DefaultAuthenticator.java,v 1.3 2004/02/19 22:38:07 scolebourne Exp $
 */
public class DefaultAuthenticator extends Authenticator
{
    /** Stores the login information for authentication */
    private PasswordAuthentication authentication;

    /**
     * Default constructor
     *
     * @param userName user name to use when authentication is requested
     * @param password password to use when authentication is requested
     */
    public DefaultAuthenticator(String userName, String password)
    {
        this.authentication = new PasswordAuthentication(
                userName, password );
    }

    /**
     * Gets the authentication object that will be used to login to the mail
     * server.
     *
     * @return A <code>PasswordAuthentication</code> object containing the
     *         login information.
     */
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return this.authentication;
    }
}

The main class

public class PruebaMail {
  public PruebaMail() {
  }

  public static void main(String[] args) {
    PruebaMail pruebamail = new PruebaMail();
    try {
Properties properties = new Properties();
      javax.mail.Authenticator authenticator = new DefaultAuthenticator(mailuser,mailpassword);
      properties.put("mail.smtp.host", mailHost);
      properties.put("mail.smtp.auth", "true");
      properties.put("mail.smtp.port", "25");
      properties.put("mail.smtp.starttls.enable", "true");

      Session session = Session.getInstance(properties, authenticator);
      session.setDebug(true);
      MimeMessage mimeMsg = new MimeMessage(session);
      mimeMsg.setFrom(new InternetAddress(mailFrom));
      mimeMsg.setRecipients(Message.RecipientType.TO, mailTo);

      mimeMsg.setSubject(mailSubject);
      MimeBodyPart part = new MimeBodyPart();
      part.setText(mailContent == null ? "" : mailContent.trim());
      part.setContent(mailContent, "text/plain;charset=UTF-8");
      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(part);
      mimeMsg.setContent(multipart);
      mimeMsg.setSentDate(new Date());
      Transport.send(mimeMsg);
    }
    catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }

0
 
mrcoffee365Commented:
Okay, where did you get the mailuser and the mailpassword from?  In this code, I don't see values for them.  Did you set them as strings, e.g.:
"aaguia", "mypassword"

You know that the mailuser is aaguia and not aaguia@domain.com, right? (for example)
0
 
aaguiaAuthor Commented:
Sure I pass them as strings and I didnt include @domain.com
0
 
mrcoffee365Commented:
It's hard to tell with what you've posted, and with what you've said you've done, but we are now back to thinking that either
1) your email user aaguia is not valid for the smtp server you are connecting to, or
2) your email password is wrong, or
3) your smtp server uses a different kind of authentication than you think it does.

As mohammedf said early on, it looks as if you have an invalid user or password.

You said you can successfully telnet to your smtp server and send an email.  Can you post that session?  We might be able to identify the actual problem from that.  Remember to remove the actual smtp server and your password.

Also -- you know that aaguia@domain.com has to be a valid user in your smtp.domain.com domain, right?  These are obvious, but since we have code we know works, we're trying to track down the pieces that are not conveyed in your information here.
0
 
aaguiaAuthor Commented:
I recheck my user and my password both are working fine, how do I know? because I have installed in the same machine outlook and their work fine and also because we have a webmail page where I use the same user and password and work fine. Maybe it could be the server authentication but the problem is how do i know which one to use? how do I know what I have to change in my java code to make it work?

About the telnet session what I said is that the first thing I tried was to open a command prompt and from there I used telnet smtp(ip) 25, I did that to check if from that computer the smtp server answer, I never send a email using telnet.
0
 
mrcoffee365Commented:
Good -- that's a good way to test that you have the right email username and the right password.

So now we're at the point where we think it's the authentication method which is wrong.

It would be a good test to send an email using telnet, because it confirms the type of authentication.

This is a good page for going through the steps of using telnet to make an authenticated login to your web server:
http://www.computerperformance.co.uk/exchange2003/exchange2003_SMTP_Auth_Login.htm

For most systems, using telnet from a command window (or a terminal window on Unix) means that you can't hit backspace, so type carefully.  If you type something wrong, quit telnet by typing quit, and start again.

If you can't send email using telnet with your username and password, then you know that your method of authentication is wrong for your server.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 12
  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now