我想制作一个antiviruse备份系统,我希望程序向用户发送一封电子邮件,然后用户创建一个帐户,包含警告和副本系统备份。用java发送电子邮件有什么好的教程吗?如何从批处理程序或java发送电子邮件
-1
A
回答
1
如果你想从批处理中发送它,真的有很多方法可以做到。
下面是一个用于Windows的方式:
下面是Linux的一种方法:
http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/
0
这里是例子: 使用Java的邮件1.4.4.jar
package net.spring.mail;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message; `enter code here`
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
/**
* javaMail发送邮件
* 支持多邮件发送
* @author fazhen.zheng
*
*/
public class EmailAttachmentSender {
public static void sendEmailWithAttachments(String host, String port,
final String userName, final String password, String toAddress,
String subject, String message, String[] attachFiles)
throws AddressException, MessagingException {
// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", port);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.user", userName);
properties.put("mail.password", password);
// creates a new session with an authenticator
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
};
Session session = Session.getInstance(properties, auth);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
// creates message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "text/html");
// creates multi-part
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// adds attachments
if (attachFiles != null && attachFiles.length > 0) {
for (String filePath : attachFiles) {
MimeBodyPart attachPart = new MimeBodyPart();
try {
attachPart.attachFile(filePath);
} catch (IOException ex) {
ex.printStackTrace();
}
multipart.addBodyPart(attachPart);
}
}
// sets the multi-part as e-mail's content
msg.setContent(multipart);
// sends the e-mail
Transport.send(msg);
}
/**
* 测试发带附件邮件
*/
public static void main(String[] args) {
// 发件人信息
String host = "smtp.163.com";
String port = "25";
String mailFrom = "[email protected]";
String password = "passwrod";
// 收件人信息
String mailTo = "[email protected]";
String subject = "javaMail";
String message = "这是一封由javaMail自动发出的测试邮件,请勿回复。";
// 附件
String[] attachFiles = new String[1];
attachFiles[0] = "c:/EHL_SysManager.jar";
try {
sendEmailWithAttachments(host, port, mailFrom, password, mailTo,
subject, message, attachFiles);
System.out.println("邮件发送成功.");
} catch (Exception ex) {
System.out.println("发送失败");
ex.printStackTrace();
}
}
}
相关问题
- 1. 如何从批处理文件发送电子邮件?
- 2. 如何从DOS批处理命令发送电子邮件?
- 3. 如何使用Spring批处理发送多个电子邮件
- 4. 如何从Windows批处理文件发送简单电子邮件?
- 5. 如何从Java Web应用程序发送电子邮件
- 6. Java电子邮件发送API电子邮件没有发送..挂断程序
- 7. 从VBA电子邮件程序发送HTML电子邮件
- 8. 发送电子邮件没有Outlook帮助(批处理文件)
- 9. 发送电子邮件处理跳动
- 10. 任务计划程序通过批处理发送电子邮件
- 11. 发送电子邮件作为“批处理执行作业”
- 12. 如何发送电子邮件在Java
- 13. 如何以Java发送电子邮件?
- 14. 如何使用java邮件从android发送电子邮件
- 15. 从批处理文件发送电子邮件的最佳方式是什么?
- 16. 发送电子邮件从java
- 17. 从java发送电子邮件
- 18. 从Java应用程序发送电子邮件的问题
- 19. 无法从Java Web应用程序发送电子邮件
- 20. 如何在heroku上使用delayed_job发送批量处理的电子邮件?
- 21. PHP的电子邮件处理程序不能发邮件
- 22. 如何从PHPmyAdmin发送电子邮件?
- 23. 如何从Node.js发送电子邮件?
- 24. 如何从ASP.Net发送电子邮件
- 25. 如何从C发送电子邮件
- 26. 发送电子邮件从
- 27. 发送批量电子邮件
- 28. 批量发送电子邮件与SwiftMailer
- 29. 以C#发送批量电子邮件#
- 30. C#发送批量电子邮件
我不知道abou t电源外壳。谢谢让我意识到它! – fftk4323 2013-03-20 13:21:43