我使用套接字通过Gmail发送邮件,但我一次又一次地收到的错误是
530 5.7.0必须先发出STARTTLS命令
public class SMTPDemo {
static InputStream inn;
private static BufferedReader in;
private static String subject;
private static String message;
public static void main(String args[]) throws IOException,
UnknownHostException {
subject="Pakistan";
message="I am Alive";
String from = "sharpzain@gmail.com";
String to = "sharpzain@gmail.com";
String mailHost = "smtp.gmail.com";
Socket smtpPipe;
smtpPipe = new Socket("smtp.gmail.com", 25);
System.out.println(smtpPipe);
OutputStream outt;
outt = smtpPipe.getOutputStream();
BufferedWriter wtr;
inn = smtpPipe.getInputStream();
in = new BufferedReader(new InputStreamReader(inn));
wtr = new BufferedWriter(new OutputStreamWriter(outt));
/*SMTP mail = new SMTP(mailHost);
if (mail != null) {
if (mail.send(new FileReader(msgFile), from, to)) {
System.out.println("Mail sent.");
} else {
System.out.println("Connect to SMTP server failed!");
}
}
System.out.println("Done.");*/
say( wtr, "HELO kth.se" );
say( wtr, "MAIL FROM: <"+from+">" );
say( wtr, "RCPT TO: <" + to + ">" );
say(wtr,"data");
say(wtr,"subject: "+subject);
say(wtr,"From: "+from);
say(wtr,"To: "+to+"\r\n");
say(wtr,message+" ");
say(wtr,"\r\n.");
say( wtr, "RSET" );
say( wtr, "QUIT" );
}
static void say( BufferedWriter wr, String text )
throws IOException {
wr.write( text + "\r\n" );
String recipientOK = in.readLine();
System.out.println(text);
System.out.println(recipientOK);
wr.flush();
}
发送HELO和FROM时需要一个OK响应,但得到响应必须在RCPT和其他命令之后发出TTLS。任何人都可以告诉我它背后的问题是什么?