I am not getting any mail from this Script. What is wrong with the coding.Page is working perfectly with my SMTP provider and its giving the output in the page. but no m ail in my mail box. - <%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
-
<%
-
String from="ajaxrand@gmail.com";
-
String to="ajaxrand@gmail.com";
-
try
-
{
-
SmtpClient client = new SmtpClient("MY.SMTP.HERE");
-
client.from(from);
-
client.to(to);
-
PrintStream message = client.startMessage();
-
out.println("To: " + to+"<BR>");
-
out.println("Subject: Sending email from JSP!<BR>");
-
out.println("This was sent from a JSP page!<BR>");
-
client.closeServer();
-
}
-
catch (IOException e)
-
{
-
out.println("ERROR SENDING EMAIL:"+e);
-
}
-
%>
-
5 3405
I don't understand what you're trying to do there. What is an SMTPClient?
This is how I send a mail message: -
import java.util.Properties;
-
import javax.mail.*;
-
import javax.mail.internet.*;
-
-
public class MailExample {
-
public static void main (String args[]) throws Exception {
-
String host = "smtp.xxxxx.xxx";
-
String to = "whatever@domain.topdomain";
-
String from = "tttttt@xxxxx.xxx";
-
-
// Get system properties
-
Properties props = System.getProperties();
-
-
// Setup mail server
-
props.put("mail.smtp.host", host);
-
-
// Get session
-
Session session = Session.getDefaultInstance(props, null);
-
-
session.setDebug(true);
-
// Define message
-
MimeMessage message = new MimeMessage(session);
-
-
// Set the from address
-
message.setFrom(new InternetAddress(from));
-
-
// Set the to address
-
message.addRecipient(Message.RecipientType.TO,
-
new InternetAddress(to));
-
-
// Set the subject
-
message.setSubject("Hello JavaMail");
-
-
// Set the content
-
message.setText("Welcome to JavaMail");
-
-
// Send message
-
Transport.send(message);
-
}
-
}
kind regards,
Jos
Sorry this script is from this URL, I think i misunderstood the coding. http://www.jguru.com/faq/view.jsp?EID=1163
Don't just copy and paste code and hope for the best: that article didn't mention
the SmtpClient (at least not on the same page). You either have to read the
entire article or stick with the javax.mail.* classes. My little example uses just
those. Programmers who simply copy and paste stuff without understanding
*what* they've just copied and pasted are never, I repeat, never good programmers.
First you have to read and understand, then you experiment and only then you
try to come up with something useful; there is no other way, believe me.
kind regards,
Jos
I needed to use pure JSP mail Script. Not a class file like yours.
Then i have to go for servlets.
Any way i made it. - <%@ page import="javax.mail.*, javax.mail.internet.*,java.util.*;" %>
-
<%
-
try
-
{
-
InternetAddress toAddress = new InternetAddress("To_mail_addres_here");
-
InternetAddress fromAddress = new InternetAddress("From_mail_addres_here");
-
Properties prp = new Properties();
-
prp.put("mail.smtp.host", "some.smtp.here");
-
Session mailsession = Session.getDefaultInstance(prp, null);
-
Message msg = new MimeMessage(mailsession);
-
msg.addRecipient(Message.RecipientType.TO, toAddress);
-
msg.setSubject("HTML Mail");
-
msg.setFrom(fromAddress);
-
msg.setContent("<B>HTML Message</B>","text/html");
-
Transport.send(msg);
-
%>
-
<b>An e-mail has been sent.</b>
-
<%
-
}
-
catch (Exception e)
-
{
-
e.printStackTrace();
-
}
-
%>
I needed to use pure JSP mail Script. Not a class file like yours.
Then i have to go for servlets.
Any way i made it.
Good; notice that my class was just a MailExample class and everything was
done from the static main() method. Not much of a class and very easy to stick
in main's code elsewhere ;-)
Good you made it; best of luck.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James Hong |
last post by:
Help please, I try to sending an email from my html page using the java
applet.
but it give error on most of the PC only very few work, what is the error i
make
the java applet show as below
...
|
by: Ravi Tallury |
last post by:
Hi
We are having issues with our application, certain portions of it stop
responding while the rest of the application is fine. I am attaching
the Java Core dump. If someone can let me know what...
|
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities...
|
by: aychai |
last post by:
Hi all,
I am trying to make use Oracle9i db to call an external .Net Web
Service from a JAva Stored Procedure.
I created the .Net Web Service and use JDeveloper 9.0.3.4Build(1247)
to create...
|
by: Eagle35 |
last post by:
hi all
im new to the whole java thing and need some help!
im trying to make an e mail form and when i test it, it sends the e mail to
the designated e mail address but when i go to the e mail...
|
by: JohnK |
last post by:
Hi all,
This is my first time visiting this group. I already tried two other java
groups, but those aren't very populated.
I don't know if it is the right one, otherwise please tell me in which...
|
by: Sai Kit Tong |
last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't
make it clear in my original mail. I got a couple of answers but none of
them address my issues directly (See attached...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: crossroadsk |
last post by:
<pre>
Hi all,
I'm new to Javamail concept and i got the following exceptions when i tried to send a simple mail.
First exception is :
using java Could not connect to SMTP host:...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |