Advertisement

09.16.2004 at 03:15AM PDT, ID: 21133318
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

JavaMail SMTP Send Mail : MAIL requires AUTH

Asked by eddie81 in Java Programming Language, JavaMail

Tags: ,

Hi all,

I am using open-source servlet to send email via SMTP. But the SMTP gateway requires authentication. Following is the error message :-

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false

DEBUG: SMTPTransport trying to connect to host "smtp1.host.com", port 25

DEBUG SMTP RCVD: 220 mail1.host.com ESMTP Mirapoint 3.4.4-GR; Thu, 16 Sep 2004 17:49:19 +0800 (MYT)

DEBUG: SMTPTransport connected to host "smtp1.host.com", port: 25

DEBUG SMTP SENT: EHLO MYNAME
DEBUG SMTP RCVD: 250-mail1.host.com Hello MYNAME.host.com [1xx.1xx.2xx.2xx], pleased to meet you
250-8BITMIME
250-SIZE 13500000
250-DSN
250-ETRN
250-STARTTLS
250 HELP

DEBUG SMTP Found extension "8BITMIME", arg ""
DEBUG SMTP Found extension "SIZE", arg "13500000"
DEBUG SMTP Found extension "DSN", arg ""
DEBUG SMTP Found extension "ETRN", arg ""
DEBUG SMTP Found extension "STARTTLS", arg ""
DEBUG SMTP Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<eddie.see@host.com>
DEBUG SMTP RCVD: 530 <eddie.see@host.com>... MAIL requires AUTH

Messaging exception: 530 <eddie.see@host.com>... MAIL requires AUTH

==> How can I enable the servlet to send email via SMTP using authentication? The SMTP Gateway is "smtp1.host.com" but it seems to be re-routed to "mail1.host.com".


My source code is as follow:-

package com.elucify.tips.oct2002;

import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.servlet.http.*;
import javax.servlet.*;

public class SendmailServlet extends HttpServlet {
    protected ServletConfig _config;
    protected Session _mailSession;
    protected String _mailhost;
    protected String _mailuser;
    protected boolean _debug;

    public SendmailServlet() {
        _config = null;
        _mailSession = null;
        _mailhost = null;
        _mailuser = null;
    }

    public void init(ServletConfig config) {
        _config = config;
        _mailhost = config.getInitParameter("mailhost");
        _mailuser = config.getInitParameter("mailuser");
    }

    // doGet and doPost do the same thing
    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
        doService(req, res);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
        doService(req, res);
    }

    protected void doService(HttpServletRequest req,
                             HttpServletResponse res)
        throws IOException, ServletException {

        res.setContentType("text/html");

        // Get (or create and cache) mail session
        Session s = getMailSession();

        // If either init parameter or request
        // parameter "debug" is set, output
        // SMTP session log to server log.
        boolean debug = false;
        String sdebug = _config.getInitParameter("debug");

        if (sdebug == null) {
            sdebug = req.getParameter("debug");
        }

        if (sdebug != null &&
            Boolean.valueOf(sdebug).booleanValue()) {
            s.setDebug(true);
        }

        // Create new message
        MimeMessage msg = new MimeMessage(s);

        // Put data from request into message
        try {
            String messageText =
                req.getParameter("messagetext");
            msg.setText(messageText);

            String subject = req.getParameter("subject");
            if (subject != null) {
                msg.setSubject(subject);
            }


                String password = req.getParameter("pwd");
            String addrFrom =
                req.getParameter("addrfrom");
            String nameFrom =
                req.getParameter("namefrom");
            Address fromAddr =
                new InternetAddress(addrFrom, nameFrom);
            msg.setFrom(fromAddr);
            String addrto = req.getParameter("addrto");
            String nameto = req.getParameter("nameto");
            Address toAddr =
                new InternetAddress(addrto, nameto);
            msg.addRecipient(Message.RecipientType.TO, toAddr);

            // Send the message
            //Transport.send(msg);
                Transport tr = _mailSession.getTransport("smtp");
                tr.connect(_mailhost, _mailuser, password);
                msg.saveChanges();
                tr.sendMessage(msg, msg.getAllRecipients());
                tr.close();

            // Print a message acknowledging that the message
            // was sent
            PrintWriter pw = res.getWriter();
            res.setContentType("text/html");
            pw.println("<HTML><BODY>Email sent" +
                       "</BODY></HTML>");

        } catch (UnsupportedEncodingException e) {
            System.err.println("Unsupported encoding: " +
                               e.getMessage());
        } catch (MessagingException m) {
            System.err.println("Messaging exception: " +
                               m.getMessage());
        }

     }

    // Open the mail session if it isn't already open.
    protected Session getMailSession()
      throws ServletException {

        // Throw exception if mail host or user are not set
        if (_mailhost == null || _mailuser == null) {
            throw new ServletException("SendmailServlet " +
              "init parameters mailhost and mailuser must " +
              "both be set in deployment descriptor");
        }

        // Create mail session if it doesn't exist
        if (_mailSession == null) {
            Properties p = new Properties();
            p.put("mail.host", _mailhost);
            p.put("mail.user", _mailuser);
            p.put("mail.smtp.auth", "true");

            // Can define and initialize other session
            // properties here, if desired
            _mailSession = Session.getDefaultInstance(p, null);
        }
        return _mailSession;
    }

}



Please help.
EddieStart Free Trial
 
Loading Advertisement...
 
[+][-]09.16.2004 at 03:30AM PDT, ID: 12073373

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 03:30AM PDT, ID: 12073374

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 05:16AM PDT, ID: 12073901

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 05:31AM PDT, ID: 12074001

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 11:01AM PDT, ID: 12077438

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 11:25PM PDT, ID: 12081767

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2004 at 01:01AM PDT, ID: 12082204

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2004 at 01:30AM PDT, ID: 12082366

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2004 at 02:13AM PDT, ID: 12082541

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2004 at 02:21AM PDT, ID: 12082581

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, JavaMail
Tags: javamail, smtp
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 4
Solution Grade: A
 
 
[+][-]10.02.2004 at 12:19AM PDT, ID: 12206328

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.02.2004 at 12:20AM PDT, ID: 12206332

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.25.2004 at 09:25AM PDT, ID: 12401805

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.25.2004 at 09:47AM PDT, ID: 12402024

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2004 at 01:00PM PDT, ID: 12448110

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11.02.2004 at 03:46AM PST, ID: 12471694

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11.10.2004 at 12:43AM PST, ID: 12542077

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.10.2004 at 12:52AM PST, ID: 12542119

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39