public boolean sendmail (String host, String to, String from,
String message, String subject, String cc){
try
{
//Created TCP Connection to server
Socket s = new Socket(host, 25);
//Open our streams.
InputStream inStream = s.getInputStream();
OutputStream outStream = s.getOutputStream();
in = new Scanner(inStream);
out = new PrintWriter(outStream, true);
//get my info!
String hostName = InetAddress.getLocalHost().getHostName();
//e-mail time!
receive();
send("HELO" + host);
receive();
send("MAIL FROM: <" + from + "\n");
receive();
send("RCPT TO: <" + to + "\n");
receive();
send("DATA");
receive();
send("DATA");
receive();
//Make sure to close the everything again!!
out.close();
in.close();
s.close();
return true;
}
catch (Exception e)
{
appendtolog("ERROR: " + e);
return false;
}
}
private void send(String s) throws IOException{
appendtolog(s);
out.print(s.replaceAll("\n", "\r\n"));
out.print("\r\n");
out.flush();
}
private void receive(){
String line = in.nextLine();
appendtolog(line);
}
がちょうどそこにどこかに添付ファイルを入れて、それは可能です...以下のようなものを持っていますか?私はそれが明らかに可能である
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream";
}
};
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
なぜJava Mail APIを使用しないのですか? –
*「APIを使用してこれを行う方法があることは分かっていますが、添付ファイルの機能を壊す方法があるのかと疑問に思っています。」*はい、もちろん可能です。独自のオペレーティングシステムを作成することもできます。質問は**になる必要があります**なぜ**? Java Mail APIは使い方が簡単で、よくテストされており、よく文書化されています... SMTPの機能を学ぶために何かしていたら分かりますが、 'MimeBodyPart'そして明らかにそうではありません... –
@TJ:私には別のAPIを使用していなければなりません... JavaMailは豚です。独自のSMTP/MIMEクライアントを作成するよりも簡単ですが、心に留めてください。 – skaffman