I want to code a simple program in java that can send mail via socket(not java.mail); I got some examples,but it doesn't work(following is the basic problems):
Should I send the mail to sender's smtp server first?(this may have to provide real username and password).
I got an example that sends to the receiver's smtp sever directly. I use gmail to test, but it failed, giving info:
530 5.7.0 Must issue a STARTTLS command first.
I think it is because gmail needs SSL socket. Then I got a simple SSL implementation to exchange "new Socket", it failed again with error info:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Maybe the SSL usage is wrong? This is the SSL code:
class Java2000TrustManager implements X509TrustManager {
Java2000TrustManager() {
}
public void checkClientTrusted(X509Certificate chain[], String authType)
throws CertificateException {
System.out.println("checkClientTrusted...");
}
public void checkServerTrusted(X509Certificate chain[], String authType)
throws CertificateException {
System.out.println("checkServerTrusted");
}
public X509Certificate[] getAcceptedIssuers() {
System.out.println("getAcceptedIssuers...");
return null;
}
}
Please give me a way to implement this successfully.