aspose file tools*
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
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending email in jsp" Watch "Sending email in jsp" New topic
Author

Sending email in jsp

Mike Schultz
Greenhorn

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"));

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

Joined: Jan 10, 2002
Posts: 60056
    
  65

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
Bartender

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending email in jsp
 
Similar Threads
SMTPSendFailedException Occurs
JAVA mail API : HTML mails are sent with html tags.
Exception while sending email from a Servlet
Sending MAIL by Java
How to embed image (relative path) in an HTML e-mail?