本文整理匯總了Java中javax.mail.Message.setSentDate方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.setSentDate方法的具體用法?Java Message.setSentDate怎麽用?Java Message.setSentDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.Message
的用法示例。
在下文中一共展示了Message.setSentDate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendTextMail
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendTextMail(MailSenderInfo mailInfo) {
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
try {
Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSentDate(new Date());
mailMessage.setText(mailInfo.getContent());
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
return false;
}
}
示例2: sendAttachMail
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendAttachMail(MailSenderInfo mailInfo) {
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
try {
Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSentDate(new Date());
Multipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
multi.addBodyPart(textBodyPart);
for (String path : mailInfo.getAttachFileNames()) {
DataSource fds = new FileDataSource(path);
BodyPart fileBodyPart = new MimeBodyPart();
fileBodyPart.setDataHandler(new DataHandler(fds));
fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
multi.addBodyPart(fileBodyPart);
}
mailMessage.setContent(multi);
mailMessage.saveChanges();
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
return false;
}
}
示例3: sendEmailWithOrder
import javax.mail.Message; //導入方法依賴的package包/類
public static void sendEmailWithOrder(String text, String eMail, HttpServletRequest request) {
try {
Session session = EmailActions.authorizeWebShopEmail();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(eMail, false));
msg.setSubject("Shop order");
msg.setText(text);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
}
示例4: sendCode
import javax.mail.Message; //導入方法依賴的package包/類
public static String sendCode(User user, HttpServletRequest request) {
try {
Session session = EmailActions.authorizeWebShopEmail();
String code = Long.toHexString(Double.doubleToLongBits(Math.random()));
request.getSession().setAttribute("deleteAccountCode", code);
request.getSession().setAttribute("userName", user.getLogin());
System.out.println(code);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(user.geteMail(), false));
msg.setSubject("Delete account");
msg.setText("Link : " + ApplicationProperties.URL + ApplicationProperties.PROJECT_NAME + "account/deleteAccountCode/" + code);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
return "loginAndRegistration/reset/codePassword";
}
示例5: sendHtmlMail
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendHtmlMail(MailSenderInfo mailInfo) {
XLog.d("發送網頁版郵件!");
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
try {
Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
String[] receivers = mailInfo.getReceivers();
Address[] tos = new InternetAddress[receivers.length];
for (int i = 0; i < receivers.length; i++) {
tos[i] = new InternetAddress(receivers[i]);
}
mailMessage.setRecipients(Message.RecipientType.TO, tos);
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSentDate(new Date());
Multipart mainPart = new MimeMultipart();
BodyPart html = new MimeBodyPart();
html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
mainPart.addBodyPart(html);
mailMessage.setContent(mainPart);
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
return false;
}
}
示例6: sendEmail
import javax.mail.Message; //導入方法依賴的package包/類
public static void sendEmail(String host, String port,
final String userName, final String password, String toAddress,
String subject, String message, String nombreArchivoAdj, String urlArchivoAdj)
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");
// 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);
//Se crea la parte del cuerpo del mensaje.
BodyPart texto = new MimeBodyPart();
texto.setText(message);
BodyPart adjunto = new MimeBodyPart();
if(nombreArchivoAdj != null ){
adjunto.setDataHandler(new DataHandler(new FileDataSource(urlArchivoAdj)));
adjunto.setFileName(nombreArchivoAdj);
}
//Juntar las dos partes
MimeMultipart multiParte = new MimeMultipart();
multiParte.addBodyPart(texto);
if (nombreArchivoAdj != null) multiParte.addBodyPart(adjunto);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = null;
toAddresses = InternetAddress.parse(toAddress, false);
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
//msg.setText(message);
msg.setContent(multiParte);
// sends the e-mail
Transport.send(msg);
}
示例7: _setupMessage
import javax.mail.Message; //導入方法依賴的package包/類
/**
* Set up a new message.
*/
private Message _setupMessage(Message msg)
{
try
{
String username = _account.getUsername();
String from = username + "@" + _account.getDomain();
List<InternetAddress> to = _getEmailList(getTo());
List<InternetAddress> cc = null;
String ccString = getCc();
if(ccString != null)
{
cc = _getEmailList(ccString);
}
msg.setFrom(new InternetAddress(from));
if ((to != null) && !to.isEmpty())
msg.setRecipients(Message.RecipientType.TO,
to.toArray(new InternetAddress[0]));
if ((cc != null) && !cc.isEmpty())
msg.setRecipients(Message.RecipientType.CC,
cc.toArray(new InternetAddress[0]));
msg.setSubject(_subject == null ? "" : _subject);
if ((_attachment1 == null) &&
(_attachment2 == null) &&
(_attachment3 == null))
{
msg.setText(_content == null ? "" : _content);
}
// Multipart.
else
{
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(_content == null ? "" : _content);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
if (_attachment1 != null)
_addAttachment(multipart, _attachment1);
if (_attachment2 != null)
_addAttachment(multipart, _attachment2);
if (_attachment3 != null)
_addAttachment(multipart, _attachment3);
// Put all the parts in the message
msg.setContent(multipart);
}
String mailer = "OracleAdfEmailDemo";
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
return msg;
}
catch(AddressException ae)
{
_showSendException(ae);
}
catch(MessagingException me)
{
_showSendException(me);
}
catch(Exception e)
{
_showSendException(e);
}
return null;
}
示例8: sendHtmlMail
import javax.mail.Message; //導入方法依賴的package包/類
/**
* 以HTML格式發送郵件
*
* @param mailInfo
* 待發送的郵件信息
*/
public boolean sendHtmlMail(MailSenderObj mailInfo) {
// 判斷是否需要身份認證
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
// 如果需要身份認證,則創建一個密碼驗證器
if (mailInfo.isValidate()) {
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
// 根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
sendMailSession.setDebug(true);// 設置debug模式 在控製台看到交互信息
try {
// 根據session創建一個郵件消息
Message mailMessage = new MimeMessage(sendMailSession);
// 創建郵件發送者地址
Address from = new InternetAddress(mailInfo.getFromAddress());
// 設置郵件消息的發送者
mailMessage.setFrom(from);
// 創建郵件的接收者地址,並設置到郵件消息中
String[] asToAddr = mailInfo.getToAddress();
if (asToAddr == null) {
logger.debug("郵件發送失敗,收信列表為空" + mailInfo);
return false;
}
for (int i=0; i<asToAddr.length; i++) {
if (asToAddr[i] == null || asToAddr[i].equals("")) {
continue;
}
Address to = new InternetAddress(asToAddr[i]);
// Message.RecipientType.TO屬性表示接收者的類型為TO
mailMessage.addRecipient(Message.RecipientType.TO, to);
}
// 設置郵件消息的主題
mailMessage.setSubject(mailInfo.getSubject());
// 設置郵件消息發送的時間
mailMessage.setSentDate(new Date());
// MiniMultipart類是一個容器類,包含MimeBodyPart類型的對象
Multipart mainPart = new MimeMultipart();
// 創建一個包含HTML內容的MimeBodyPart
BodyPart html = new MimeBodyPart();
// 設置HTML內容
html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
mainPart.addBodyPart(html);
// 將MiniMultipart對象設置為郵件內容
mailMessage.setContent(mainPart);
// 發送郵件
Transport.send(mailMessage);
logger.info("發送郵件成功。" + mailInfo);
return true;
} catch (MessagingException ex) {
logger.error("發送郵件失敗:" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
}
return false;
}
示例9: sendCode
import javax.mail.Message; //導入方法依賴的package包/類
@RequestMapping(value = "sendCode", method = RequestMethod.POST)
public String sendCode(@RequestParam("login") String login, @RequestParam("email") String email, Model model,
HttpServletResponse response, HttpServletRequest request) {
if ((usersService.findByEmail(email) == null)) {
model.addAttribute("msg", "Wrong e-mail");
return "loginAndRegistration/reset/forgotPassword";
} else if (usersService.findByLogin(login) == null) {
model.addAttribute("msg", "Wrong login");
return "loginAndRegistration/reset/forgotPassword";
}
try {
Session session = EmailActions.authorizeWebShopEmail();
String code = Long.toHexString(Double.doubleToLongBits(Math.random()));
request.getSession().setAttribute("code", code);
request.getSession().setAttribute("email", email);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
msg.setSubject("Reset password");
msg.setText("After 5 min code will be delete\n" + code);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
return "loginAndRegistration/reset/codePassword";
}
示例10: sendUsername
import javax.mail.Message; //導入方法依賴的package包/類
@RequestMapping(value = "sendUsername", method = RequestMethod.POST)
public String sendUsername(@RequestParam("email") String email, Model model, HttpServletResponse response,
HttpServletRequest request) {
if ((usersService.findByEmail(email) == null)) {
model.addAttribute("msg", "Wrong e-mail");
return "loginAndRegistration/reset/forgotUsername";
}
User user = usersService.findByEmail(email);
try {
Session session = EmailActions.authorizeWebShopEmail();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
msg.setSubject("Your login");
msg.setText("Login : " + user.getLogin());
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
model.addAttribute("msg", "Success");
return "loginAndRegistration/reset/forgotUsername";
}
示例11: emailPassword
import javax.mail.Message; //導入方法依賴的package包/類
private boolean emailPassword(String password, String username, String email) {
/* Default to protocol smtp when SmtpEncryption is set to "None" */
String prot = "smtp";
if (settingsService.getSmtpServer() == null || settingsService.getSmtpServer().isEmpty()) {
LOG.warn("Can not send email; no Smtp server configured.");
return false;
}
Properties props = new Properties();
if (settingsService.getSmtpEncryption().equals("SSL/TLS")) {
prot = "smtps";
props.put("mail." + prot + ".ssl.enable", "true");
} else if (settingsService.getSmtpEncryption().equals("STARTTLS")) {
prot = "smtp";
props.put("mail." + prot + ".starttls.enable", "true");
}
props.put("mail." + prot + ".host", settingsService.getSmtpServer());
props.put("mail." + prot + ".port", settingsService.getSmtpPort());
/* use authentication when SmtpUser is configured */
if (settingsService.getSmtpUser() != null && !settingsService.getSmtpUser().isEmpty()) {
props.put("mail." + prot + ".auth", "true");
}
Session session = Session.getInstance(props, null);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(settingsService.getSmtpFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
message.setSubject("Airsonic Password");
message.setText("Hi there!\n\n" +
"You have requested to reset your Airsonic password. Please find your new login details below.\n\n" +
"Username: " + username + "\n" +
"Password: " + password + "\n\n" +
"--\n" +
"Your Airsonic server\n" +
"airsonic.github.io/");
message.setSentDate(new Date());
Transport trans = session.getTransport(prot);
try {
if (props.get("mail." + prot + ".auth") != null && props.get("mail." + prot + ".auth").equals("true")) {
trans.connect(settingsService.getSmtpServer(), settingsService.getSmtpUser(), settingsService.getSmtpPassword());
} else {
trans.connect();
}
trans.sendMessage(message, message.getAllRecipients());
} finally {
trans.close();
}
return true;
} catch (Exception x) {
LOG.warn("Failed to send email.", x);
return false;
}
}
示例12: sendMail
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendMail(String to,String otp) throws MessagingException
{
String host="smtp.gmail.com";
String username="";//emailid
String password="";//emailid password
String from=" ";// email from which u have to send
String subject="One Time Password";
String body="Your One Time passsword is "+otp;
boolean sessionDebug=false;
Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "25");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress [] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(body);
Transport tr=mailSession.getTransport("smtp");
tr.connect(host,username,password);
msg.saveChanges();
tr.sendMessage(msg,msg.getAllRecipients());
tr.close();
//Transport.send(msg);
return true;
}
示例13: sendMail1
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendMail1(String to,String passwrd, String link) throws MessagingException
{
String host="smtp.gmail.com";
String username=" ";//emailid
String password="";//emailid password
String from=" ";// email from which u have to send
String subject="Website Password";
String body="Your website password is "+passwrd+" Please click to reset "+link;
boolean sessionDebug=false;
Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "25");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress [] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(body);
Transport tr=mailSession.getTransport("smtp");
tr.connect(host,username,password);
msg.saveChanges();
tr.sendMessage(msg,msg.getAllRecipients());
tr.close();
//Transport.send(msg);
return true;
}
示例14: sendMail2
import javax.mail.Message; //導入方法依賴的package包/類
public boolean sendMail2(String to, String link) throws AddressException, MessagingException {
String host="smtp.gmail.com";
String username=" ";//emailid
String password="";//emailid password
String from=" ";// email from which u have to send
String subject="Website Password";
String body="Activation Link"+link+"Please click to reset "+link;
boolean sessionDebug=false;
Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "25");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress [] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(body);
Transport tr=mailSession.getTransport("smtp");
tr.connect(host,username,password);
msg.saveChanges();
tr.sendMessage(msg,msg.getAllRecipients());
tr.close();
//Transport.send(msg);
return true;
}
示例15: sendTextMail
import javax.mail.Message; //導入方法依賴的package包/類
/**
* 以文本格式發送郵件
*
* @param mailInfo
* 待發送的郵件的信息
*/
public boolean sendTextMail(MailSenderObj mailInfo) {
// 判斷是否需要身份認證
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
// 如果需要身份認證,則創建一個密碼驗證器
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
// 根據郵件會話屬性和密碼驗證器構造一個發送郵件的session
Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
try {
// 根據session創建一個郵件消息
Message mailMessage = new MimeMessage(sendMailSession);
// 創建郵件發送者地址
Address from = new InternetAddress(mailInfo.getFromAddress());
// 設置郵件消息的發送者
mailMessage.setFrom(from);
// 創建郵件的接收者地址,並設置到郵件消息中
String[] asToAddr = mailInfo.getToAddress();
if (asToAddr == null) {
logger.debug("郵件發送失敗,收信列表為空" + mailInfo);
return false;
}
for (int i=0; i<asToAddr.length; i++) {
if (asToAddr[i] == null || asToAddr[i].equals("")) {
continue;
}
Address to = new InternetAddress(asToAddr[i]);
mailMessage.addRecipient(Message.RecipientType.TO, to);
}
// 設置郵件消息的主題
mailMessage.setSubject(mailInfo.getSubject());
// 設置郵件消息發送的時間
mailMessage.setSentDate(new Date());
// 設置郵件消息的主要內容
String mailContent = mailInfo.getContent();
mailMessage.setText(mailContent);
// 發送郵件
Transport.send(mailMessage);
logger.info("發送郵件成功。" + mailInfo);
return true;
} catch (MessagingException ex) {
logger.error("發送郵件失敗:" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
ex.printStackTrace();
}
return false;
}