aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes SMTP server connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SMTP server connections" Watch "SMTP server connections" New topic
Author

SMTP server connections

harmeet bawa
Greenhorn

Joined: Sep 12, 2004
Posts: 22
I have a doubt about SMTP server connections. I use a SMTP server to send out emails from our office here. Theres a java program to do this. If I send out this programs class file to other people, will they be able to use the same smtp server connection? do they need to authenticate to the server? or do i have to use their smtp servers in the program instead of ours so that the email is sent out? If I have to do that what is the way to find out from windows what SMTP server a user is using?

thanks
Harmeet
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

You can use any SMTP server that you have an ip address to.
If the SMTP server requires athentication then you must send a username and a password to

// Mathias


SCJP1.4
harmeet bawa
Greenhorn

Joined: Sep 12, 2004
Posts: 22
This is what I am looking for exactly. I have a java program that connects to our smtp server. I sent out the class file to other people so that they can use it to send out emails. This dosent seem to work. So is it that I need to find out their smpt servers and then send out emails using their smtp servers. And if I can do that, how do I do it in windows.wither xp or nt.

thanks
harmeet
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

You can't use any SMTP server unless it is configured to allow you to use it. And that "you" means your friends too.

It is a bad idea to let anybody connect to an SMTP server from anywhere in the world, because that lets people use the SMTP server to send unsolicited e-mails. (You should recognize that as "spam".) So the servers are normally configured so that only certain IP addresses can connect to it and send messages, or so that only programs that authenticate themselves can do that. I am certain that one of those two configurations has been done on the SMTP server that you are using.

If you send that class file to somebody else, and it does authentication through a hard-coded password for example, then you're sending the keys to one of your company's doors to somebody outside the company. This is obviously not a good practice security-wise and it could get you into trouble. Even if this isn't the case, the program is still a corporate asset that is not yours to give away. You should talk to the administrator of your SMTP server to see if he/she will give your friends access to the server.

However, I can't figure out why you would even want to do that. It's extremely easy for people to get access to internet e-mail.
harmeet bawa
Greenhorn

Joined: Sep 12, 2004
Posts: 22
my program runs a couple of routines, downloads some files over ftp. after successful completion of all the steps the last stage in the program is to send out an email to the users account that there were no errors. how do i go about doing this?

thanks
harmeet
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
If you want to send email use the Java mail api. Set the SMTp server to your local smtp server and send the mail.

harmeet bawa
Greenhorn

Joined: Sep 12, 2004
Posts: 22
sending out an email is not an issue at this time. i have used javamail api as well as the jakarta commons email to send the email out. Well for myself i can use my local smtp server. but if i am sending this programs class file ot other ppl to send out emails, its not going to work for them. is there a way in wondows where i can find out a users smtp server and plug it in my program, so that they can send out the email.

thanks in advance
harmeet
harmeet bawa
Greenhorn

Joined: Sep 12, 2004
Posts: 22
i have tried using gmails sinetfactory to snd out the emails. i did it from 3 systems here in my office. the code:

import com.jscape.inet.smtpssl.*;
import com.jscape.inet.email.*;
import com.sun.net.ssl.internal.ssl.Provider;
import com.sun.net.ssl.TrustManager.*;

public class SmtpGmail {

public static void main(String[] args) {
SmtpSsl smtp = null;

// gmail username - CHANGE THIS
String username = "yourusername@gmail.com";

// gmail password - CHANGE THIS
String password = "yourpassword";

// address to send mail to - CHANGE THIS
String to = "xyz@xyz.com";
try {
// create a new SmtpSsl instance connecting securely via port 465 using implicit SSL
smtp = new SmtpSsl("smtp.gmail.com",465);

// establish secure connection
smtp.connect();

// login using gmail account details
smtp.login(username,password);

// create new email message
EmailMessage message = new EmailMessage();
message.setTo(to);
message.setFrom(username);
message.setSubject("Sending email via Gmail SMTP");
message.setBody("This is the body of the message");

// send message
smtp.send(message);

// disconnect
smtp.disconnect();
} catch(Exception e) {
// capture any exception and print to console
e.printStackTrace();
}
}
}

this thing worked here. but then i logged in to a remote server and tried the same thing. this is the response:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/net/ssl/Trust
Manager
at com.jscape.inet.ipclientssl.SecureSocket.getTrustAllManagers(Unknown
Source)
at com.jscape.inet.ipclientssl.SecureSocket.<init>(Unknown Source)
at com.jscape.inet.ipclientssl.IpClientSsl.connect(Unknown Source)
at com.jscape.inet.smtpssl.SmtpSsl.connect(Unknown Source)
at SmtpGmail.main(SmtpGmail.java:24)

if i can get some help on this it will be wonderful. cant get why it is complaining here abt a missing class.

thanks
harmeet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SMTP server connections