The moose likes Other JSE/JEE APIs and the fly likes Sending email in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending email in jsp" Watch "Sending email in jsp" New topic

Sending email in jsp

Mike Schultz

Joined: Dec 14, 2004
Posts: 3
I need help in sending email in jsp. I've been using JavaMail, and I edited this code snippet from http://www.rgagnon.com/javadetails/java-0321.html
into this:


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

import java.util.Properties;

public class SimpleMail {
public static void main(String[] args) throws Exception{
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp.gmail.com");
props.setProperty("mail.host", "pop.gmail.com");
props.setProperty("mail.user", "my_username");
props.setProperty("mail.password", "my_password");

Session mailSession = Session.getDefaultInstance(props, null);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("mike_s_6@yahoo.com"));



However, when I compile and run it, it says:
Exception in thread "main" javax.mail.NoSuchProviderException: No provider for smtp.gmail.com at javax.mail.Session.getProvider(Session.java:436) at javax.mail.Session.getTransport(Session.java:631) at javax.mail.Session.getTransport(Session.java:612) at javax.mail.Session.getTransport(Session.java:598) at SimpleMail.main(SimpleMail.java:17)

Can anyone please help me? It's for a project, and it's quite urgent. ><
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60783

Sicne this is pretty much JSP-independent, I'm moving it to the "other APIs" forum where JavaMail is usually discussed.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You are configuring JavaMail to use a protocol called "smtp.gmail.com" which doesn't exist. However, SMTP does.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
It is sorta covered in the JavaRanch Style Guide.
subject: Sending email in jsp
Similar Threads
JAVA mail API : HTML mails are sent with html tags.
How to embed image (relative path) in an HTML e-mail?
Exception while sending email from a Servlet
SMTPSendFailedException Occurs
Sending MAIL by Java