当前位置: 技术问答>java相关
各位前辈,谁有最简单的java发Email的程序,让小弟看看,先谢过了!
来源: 互联网 发布时间:2014-12-31
本文导语: 各位前辈,谁有最简单的java发Email的程序,让小弟看看,先谢过了! 有聊天室的就更好了,谢谢,谢谢!!! | import java.net.*; import java.io.*; import java.net.*; public class sendElvisMail {...
各位前辈,谁有最简单的java发Email的程序,让小弟看看,先谢过了!
有聊天室的就更好了,谢谢,谢谢!!!
有聊天室的就更好了,谢谢,谢谢!!!
|
import java.net.*;
import java.io.*;
import java.net.*;
public class sendElvisMail {
public static void main(String s[]) {
//
// Send fake mail from Elvis Presley
//
// sendElvisMail [mail server] [recipient address]
// mail server can be hostname or IP address
//
// ex. sendElvisMail mail.company.com myFriend@somewhere.qc.ca
//
sendElvisMail t = new sendElvisMail();
t.sendMail(s[0], s[1]);
}
public void sendMail(String mailServer, String recipient) {
try {
Socket s = new Socket(mailServer, 25);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream(), "8859_1"));
BufferedWriter out = new BufferedWriter
(new OutputStreamWriter(s.getOutputStream(), "8859_1"));
send(in, out, "HELO theWorld");
// warning : some mail server validate the sender address
// in the MAIL FROm command, put your real address here
send(in, out, "MAIL FROM: ");
send(in, out, "RCPT TO: " + recipient);
send(in, out, "DATA");
send(out, "Subject: In the ghetto");
send(out, "From: Elvis Presley ");
send (out, "n");
// message body
send(out, "你好!");
send(out, "n.n");
send(in, out, "QUIT");
s.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
public void send(BufferedReader in, BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
s = in.readLine();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void send(BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
import java.io.*;
import java.net.*;
public class sendElvisMail {
public static void main(String s[]) {
//
// Send fake mail from Elvis Presley
//
// sendElvisMail [mail server] [recipient address]
// mail server can be hostname or IP address
//
// ex. sendElvisMail mail.company.com myFriend@somewhere.qc.ca
//
sendElvisMail t = new sendElvisMail();
t.sendMail(s[0], s[1]);
}
public void sendMail(String mailServer, String recipient) {
try {
Socket s = new Socket(mailServer, 25);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream(), "8859_1"));
BufferedWriter out = new BufferedWriter
(new OutputStreamWriter(s.getOutputStream(), "8859_1"));
send(in, out, "HELO theWorld");
// warning : some mail server validate the sender address
// in the MAIL FROm command, put your real address here
send(in, out, "MAIL FROM: ");
send(in, out, "RCPT TO: " + recipient);
send(in, out, "DATA");
send(out, "Subject: In the ghetto");
send(out, "From: Elvis Presley ");
send (out, "n");
// message body
send(out, "你好!");
send(out, "n.n");
send(in, out, "QUIT");
s.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
public void send(BufferedReader in, BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
s = in.readLine();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void send(BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
import java.io.*;
import java.util.*;
import sun.net.smtp.*;
import sun.net.*;
public class email {
public email(){
}
public void send(String from, String to, String subject, String message) {
try {
SmtpClient client = new SmtpClient("smtp.163.com");
System.out.println( "*** sendEMail : new SmtpClient");
client.from(from);
System.out.println( "*** sendEMail : client.from( from )");
client.to(to);
System.out.println( "*** sendEMail : client.to( to )");
PrintStream ps = client.startMessage();
System.out.println( "*** sendEMail : client.startMessage()");
ps.println("Subject: " + "hi");
ps.println();
System.out.println( "*** sendEMail : ps.println()");
ps.println(message);
System.out.println( "*** sendEMail : ps.println(message )");
client.closeServer();
System.out.println( "*** sendEMail : Sending sucssesful!");
}
catch( Exception ex ) {
System.out.println( "--- sendEMail : Sending failed: " + ex.getMessage() );
}
}
public static void main(String args[]){
email mymail = new email();
String subject = "Send email from administration NETA";
String message = "ni hao!";
mymail.send("bootcool@163.com","bootcool@263.net",subject,message);
}
}
import java.util.*;
import sun.net.smtp.*;
import sun.net.*;
public class email {
public email(){
}
public void send(String from, String to, String subject, String message) {
try {
SmtpClient client = new SmtpClient("smtp.163.com");
System.out.println( "*** sendEMail : new SmtpClient");
client.from(from);
System.out.println( "*** sendEMail : client.from( from )");
client.to(to);
System.out.println( "*** sendEMail : client.to( to )");
PrintStream ps = client.startMessage();
System.out.println( "*** sendEMail : client.startMessage()");
ps.println("Subject: " + "hi");
ps.println();
System.out.println( "*** sendEMail : ps.println()");
ps.println(message);
System.out.println( "*** sendEMail : ps.println(message )");
client.closeServer();
System.out.println( "*** sendEMail : Sending sucssesful!");
}
catch( Exception ex ) {
System.out.println( "--- sendEMail : Sending failed: " + ex.getMessage() );
}
}
public static void main(String args[]){
email mymail = new email();
String subject = "Send email from administration NETA";
String message = "ni hao!";
mymail.send("bootcool@163.com","bootcool@263.net",subject,message);
}
}
|
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Demo app that shows how to construct and send an RFC822
* (singlepart) message.
*
* XXX - allow more than one recipient on the command line
*
* @author Max Spivak
* @author Bill Shannon
*/
public class msgsend {
public static void main(String[] argv) {
new msgsend(argv);
}
public msgsend(String[] argv) {
String to, subject = null, from = null,
cc = null, bcc = null, url = null;
String mailhost = null;
String mailer = "msgsend";
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
int optind;
for (optind = 0; optind
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
/**
* Demo app that shows how to construct and send an RFC822
* (singlepart) message.
*
* XXX - allow more than one recipient on the command line
*
* @author Max Spivak
* @author Bill Shannon
*/
public class msgsend {
public static void main(String[] argv) {
new msgsend(argv);
}
public msgsend(String[] argv) {
String to, subject = null, from = null,
cc = null, bcc = null, url = null;
String mailhost = null;
String mailer = "msgsend";
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
int optind;
for (optind = 0; optind