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 3402
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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...
| |