Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending email in jsp

 
Mike Schultz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));

transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}

--------------------------------

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
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sicne this is pretty much JSP-independent, I'm moving it to the "other APIs" forum where JavaMail is usually discussed.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You are configuring JavaMail to use a protocol called "smtp.gmail.com" which doesn't exist. However, SMTP does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic