Sending mail using auth for server
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nuri_Besen
Posted On:   Sunday, May 12, 2002 11:54 PM

I am trying to send mail thru my server by providing user/pwd. I was successful in sending mail without auth. Sample code is: Properties props = new Properties(); props.put("mail.smtp.host", m_mailHost); if (m_debug!=0) props.put("mail.debug", "true"); if (m_user!=null) props.put("mail.smtp.auth", "true"); m_mailSession = Session.getDefaultInstance(props, null); if (m_debug!=0) m_mailSession.setDebug(true); try { m_mailTransport = m_mailSession.getTransport("smtp"); m_mailTransport.connect(m_mailHost, m_user, m_user   More>>

I am trying to send mail thru my server by providing user/pwd. I was successful in sending mail without auth.



Sample code is:



Properties props = new Properties();

props.put("mail.smtp.host", m_mailHost);

if (m_debug!=0) props.put("mail.debug", "true");

if (m_user!=null) props.put("mail.smtp.auth", "true");




m_mailSession = Session.getDefaultInstance(props, null);

if (m_debug!=0) m_mailSession.setDebug(true);




try

{

m_mailTransport = m_mailSession.getTransport("smtp");

m_mailTransport.connect(m_mailHost, m_user, m_userPass);

}

catch (Exception e)

{

e.printStackTrace();

m_mailTransport = null;

}








but it throws an AuthFailExcep when trying to connect. I know the user/pwd is correct because I use it within the MS Outlook as well.




Any ideas as to what I forgot to set? I also used a session.setPasswordAuth(new URLName,new PasswordAuth) but no success either.




Any help is greatly appreciated.




Nuri

   <<Less

Re: Sending mail using auth for server

Posted By:   jigesh_vachhrajani  
Posted On:   Tuesday, May 14, 2002 04:28 AM


Hi Nuri,

try
{
m_mailTransport = m_mailSession.getTransport("smtp");
m_mailTransport.connect(m_mailHost, m_user, m_userPass);
}

append the bolow mentioned part in your code,

try
{
.........
msg.saveChanges(); // don't forget this
m_mailTransport.sendMessage(msg, msg.getAllRecipients());
m_mailTransport.close();
}......

Hope it helps,
Love,
Jigesh.
About | Sitemap | Contact