我写了一个发送mail的类,如下
import java.io.*;
import sun.net.smtp.SmtpClient;
public class Mail
{
public Mail()
{
}
public boolean sendMail(String from, String to, String subject, String content)
{
boolean result = false;
from="
xxxxx@163.com";
to="
xxxxxxx@163.com";
subject = "Sending email from Java!";
content = "Here write contents.";
try
{
SmtpClient client = new SmtpClient("smtp.163.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: " + subject);
message.println();
message.println("This was sent from a Java!");
message.println();
message.println("Cool class! :-)");
message.println();
message.println(content);
message.println();
client.closeServer();
result = true;
}
catch (IOException e)
{
System.out.println("ERROR SENDING EMAIL:"+e);
result = false;
}
finally
{
return result;
}
}
}
我在Win2k环境下试验,系统要求进行身份验证,请指教如何实现?希望写出源码。