本文整理匯總了Java中javax.mail.Message.saveChanges方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.saveChanges方法的具體用法?Java Message.saveChanges怎麽用?Java Message.saveChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.Message
的用法示例。
在下文中一共展示了Message.saveChanges方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例2: send
import javax.mail.Message; //導入方法依賴的package包/類
public void send ( final String subject, final String text ) throws MessagingException
{
final Message message = new MimeMessage ( this.session );
if ( this.from != null )
{
message.setFrom ( this.from );
}
else
{
message.setFrom ();
}
message.setHeader ( "Return-Path", "<>" );
message.setRecipients ( javax.mail.Message.RecipientType.TO, this.to );
message.setSubject ( subject );
message.setText ( text );
message.saveChanges ();
final Transport transport = this.session.getTransport ();
logger.debug ( "Connecting transport..." );
transport.connect ();
logger.debug ( "Connecting transport... done!" );
try
{
logger.debug ( "Sending message..." );
transport.sendMessage ( message, message.getAllRecipients () );
logger.debug ( "Sending message... done!" );
}
finally
{
logger.debug ( "Closing transport..." );
try
{
transport.close ();
logger.debug ( "Closing transport... done!" );
}
catch ( final Exception e )
{
logger.info ( "Failed to close transport", e );
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}