You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Garthfield Carter <to...@webconexion.net> on 2007/07/13 12:07:30 UTC
JavaMail SMTP authentication in JSP
Hello,
Has anybody got an example they could send me of how to authenticate
with an SMTP server to send an email in JSP for JavaMail? I've been
trying unsuccessfully for two days trying to get something working. I'm
just trying in plain text at the moment, I don't need SSL or anything.
Below is the non-functioning code example I've built from various
examples on Google. None of the examples on Google that I searched for
gave a complete example just snippets. There's something that I'm doing
wrong.
Any helpe would be greatly appreciated.
Garthfield
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
String host = "smtp.domain.com";
String user = "user@domain.com";
String pass = "pAsWoRd";
String to = "to@domain.com";
String from = "from@domain.com";
String subject = "Test subject";
String messageText = "Test body";
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, user);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
%>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JavaMail SMTP authentication in JSP
Posted by "Mark H. Wood" <mw...@IUPUI.Edu>.
If you *do* get it working with TLS, I'd appreciate hearing how.
--
Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
Typically when a software vendor says that a product is "intuitive" he
means the exact opposite.
Re: JavaMail SMTP authentication in JSP
Posted by Garthfield Carter <to...@webconexion.net>.
Mildly embarrasing, but the below example works. Please ignore this
thread. Really ought to have tested my last change sorry.
Garthfield
Garthfield Carter wrote:
> Hello,
>
> Has anybody got an example they could send me of how to authenticate
> with an SMTP server to send an email in JSP for JavaMail? I've been
> trying unsuccessfully for two days trying to get something working.
> I'm just trying in plain text at the moment, I don't need SSL or
> anything. Below is the non-functioning code example I've built from
> various examples on Google. None of the examples on Google that I
> searched for gave a complete example just snippets. There's something
> that I'm doing wrong.
>
> Any helpe would be greatly appreciated.
>
> Garthfield
>
> <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
>
> <%
>
> String host = "smtp.domain.com";
> String user = "user@domain.com";
> String pass = "pAsWoRd";
>
> String to = "to@domain.com";
> String from = "from@domain.com";
> String subject = "Test subject";
> String messageText = "Test body";
> boolean sessionDebug = false;
>
> Properties props = System.getProperties();
> props.put("mail.host", host);
> props.put("mail.transport.protocol", "smtp");
>
> Session mailSession = Session.getDefaultInstance(props, null);
> mailSession.setDebug(sessionDebug);
>
> Message msg = new MimeMessage(mailSession);
> msg.setFrom(new InternetAddress(from));
> InternetAddress[] address = {new InternetAddress(to)};
> msg.setRecipients(Message.RecipientType.TO, address);
> msg.setSubject(subject);
> msg.setSentDate(new Date());
> msg.setText(messageText);
>
> Transport transport = mailSession.getTransport("smtp");
> transport.connect(host, user, user);
> transport.sendMessage(msg, msg.getAllRecipients());
> transport.close();
>
> %>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: JavaMail SMTP authentication in JSP
Posted by Lyallex <ly...@gmail.com>.
properties.put("mail.smtp.auth", "true");
...
transport.connect(host, user, pass);
possibly ?
rgds
Duncan
On 7/13/07, Garthfield Carter <to...@webconexion.net> wrote:
> Hello,
>
> Has anybody got an example they could send me of how to authenticate
> with an SMTP server to send an email in JSP for JavaMail? I've been
> trying unsuccessfully for two days trying to get something working. I'm
> just trying in plain text at the moment, I don't need SSL or anything.
> Below is the non-functioning code example I've built from various
> examples on Google. None of the examples on Google that I searched for
> gave a complete example just snippets. There's something that I'm doing
> wrong.
>
> Any helpe would be greatly appreciated.
>
> Garthfield
>
> <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
>
> <%
>
> String host = "smtp.domain.com";
> String user = "user@domain.com";
> String pass = "pAsWoRd";
>
> String to = "to@domain.com";
> String from = "from@domain.com";
> String subject = "Test subject";
> String messageText = "Test body";
> boolean sessionDebug = false;
>
> Properties props = System.getProperties();
> props.put("mail.host", host);
> props.put("mail.transport.protocol", "smtp");
>
> Session mailSession = Session.getDefaultInstance(props, null);
> mailSession.setDebug(sessionDebug);
>
> Message msg = new MimeMessage(mailSession);
> msg.setFrom(new InternetAddress(from));
> InternetAddress[] address = {new InternetAddress(to)};
> msg.setRecipients(Message.RecipientType.TO, address);
> msg.setSubject(subject);
> msg.setSentDate(new Date());
> msg.setText(messageText);
>
> Transport transport = mailSession.getTransport("smtp");
> transport.connect(host, user, user);
> transport.sendMessage(msg, msg.getAllRecipients());
> transport.close();
>
> %>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org