源程序如下:
String host = "b2b-chain";
String from = "[email protected]";
String to = "[email protected]";
String fileAttachment = "c:\boot.ini"; // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.smtp.host", host); // Get session
Session session =
Session.getInstance(props, null); // Define message
MimeMessage message =
new MimeMessage(session);
message.setFrom(
new InternetAddress(from));
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(
"Hello JavaMail Attachment"); // create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart(); //fill message
messageBodyPart.setText("Hi"); Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart); // Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart); // Put parts in message
message.setContent(multipart); // Send the message
try
{
Transport.send( message );
}
catch(Exception e)
{
System.out.println("-----------\n" + e.toString() + "\n-----------");
}
String host = "b2b-chain";
String from = "[email protected]";
String to = "[email protected]";
String fileAttachment = "c:\boot.ini"; // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.smtp.host", host); // Get session
Session session =
Session.getInstance(props, null); // Define message
MimeMessage message =
new MimeMessage(session);
message.setFrom(
new InternetAddress(from));
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(
"Hello JavaMail Attachment"); // create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart(); //fill message
messageBodyPart.setText("Hi"); Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart); // Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart); // Put parts in message
message.setContent(multipart); // Send the message
try
{
Transport.send( message );
}
catch(Exception e)
{
System.out.println("-----------\n" + e.toString() + "\n-----------");
}
就是用163的,也不是163。com,也是SMTP。163。COM。
而且现在smtp好象都要认证。
Session session = Session.getInstance(props,autho);