on 08-23-2006 5:41 AM
Hi,
'm trying to send mails from my webdynpro application, and I used SMTP. for that i downloaded jscape.inetfactory. and the following pgm i wrote.
No compilation error.. But exception comes.. it is given at the end...
-
CODE----
import com.jscape.inet.smtp.*;
import com.jscape.inet.mime.*;
import com.jscape.inet.email.*;
import java.io.*;
public static void main(String[] args) {
}
public class Testsmtp extends SmtpAdapter {
public void sendMessage(String hostname, String to, String from, String subject, String body, String attachment) throws SmtpException,
IOException, MimeException {
// create new Smtp instance
Smtp smtp = new Smtp(hostname);
// enable debugging
smtp.setDebug(true);
// register this class to capture SMTP related events
smtp.addSmtpListener(this);
// connect to SMTP server
smtp.connect();
// create email message
EmailMessage email = new EmailMessage();
email.setTo(to);
email.setFrom(from);
email.setSubject(subject);
email.setBody(body);
// add attachment to email message
//email.addAttachment(new Attachment(new File(attachment)));
// send email message
smtp.send(email);
// disconnect from SMTP server
smtp.disconnect();
}
// capture connect event
public void connected(SmtpConnectedEvent evt) {
System.out.println("Connected to SMTP server: " + evt.getHostname());
}
// capture disconnect event
public void disconnected(SmtpDisconnectedEvent evt) {
System.out.println("Disconnected from SMTP server: " + evt.getHostname());
}
public static void main(String[] args) {
String hostname;
String to;
String from;
String subject;
String body;
String attach;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter SMTP hostname (e.g. mail.domain.com): ");
hostname = reader.readLine();
System.out.print("Enter To address (e.g. recipient@domain.com): ");
to = reader.readLine();
System.out.print("Enter From address (e.g. sender@domain.com): ");
from = reader.readLine();
subject = "iNet Factory Attachment Example";
body = "see attached image";
attach = "image.gif";
Testsmtp example = new Testsmtp();
example.sendMessage(hostname,to,from,subject,body,attach);
System.out.println("sent");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
-
Output-Exception----
Enter SMTP hostname (e.g. mail.domain.com): mail.enteg.com
Enter To address (e.g. recipient@domain.com): smitha.s@enteg.com
Enter From address (e.g. sender@domain.com): jesmila.s@enteg.com
com.jscape.inet.smtp.SmtpException: an I/O error occured: Could not connect for 30000 milliseconds
at com.jscape.inet.smtp.Smtp.connect(Unknown Source)
at Testsmtp.sendMessage(Testsmtp.java:36)
at Testsmtp.main(Testsmtp.java:84)
hi
If the exception is unknown source then check for the hostname that you are providing.You can also provide the IP address of the SMTP/POP server instead of the hostname.
some SMTP Server also require authentication.in your code i didn`t find any property for Username & password that is being supplied,so i assume it is not required as you have already signed on to the application.Also check if the SMTP server that you are trying to connect allows connection directly.If it doesnot allow then contact your system admin & ask him to allow requests comming from your machine i.e IP address to access the server.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.