本文整理匯總了Java中javax.mail.internet.AddressException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java AddressException.printStackTrace方法的具體用法?Java AddressException.printStackTrace怎麽用?Java AddressException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.AddressException
的用法示例。
在下文中一共展示了AddressException.printStackTrace方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendMail
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
public void sendMail(String host, String from, String to, String subject, String messageText) {
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(messageText);
Transport.send(msg);
} catch (AddressException ae) {
ae.printStackTrace(System.out);
} catch (MessagingException me) {
me.printStackTrace(System.out);
}
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:20,代碼來源:MailServiceBean.java
示例2: isEmail
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
/**
* Validate that this email address conforms to the syntax rules of RFC 822.
*
*
* @param email
* @param charLimit
* @return true or false
*
*
*/
public static boolean isEmail( String email, int charLimit )
{
if( email.length() > charLimit ) return false;
try
{
InternetAddress internetAddress = new InternetAddress(email);
internetAddress.validate();
return true;
}catch( AddressException e )
{
if( Config.DEBUG_MODE ) e.printStackTrace();
return false;
}
}
示例3: sendFromGMail
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
/**
* send an email to the desired recipients
* @param from the email address of the sender
* @param pass the password of the sender
* @param to A String[] containing the recipients
* @param subject a String containing the subject of the email
* @param body a String containing the message to be sent
*/
private static void sendFromGMail(String from, String pass, String[] to, String subject, String body) {
Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session =Session.getInstance(props); //Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
// To get the array of addresses
for( int i = 0; i < to.length; i++ ) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
}
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch (AddressException ae) {
System.out.println("error"+ae.getLocalizedMessage());
ae.printStackTrace();
}
catch (MessagingException me) {
me.printStackTrace();
}
}
示例4: sendSystemEmail
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
public boolean sendSystemEmail(String to, String subject, String messageText,
Locale locale) {
boolean sent = false;
try {
Message msg = new MimeMessage(session);
InternetAddress systemAddress = getSystemAddress();
if (systemAddress != null) {
msg.setFrom(systemAddress);
msg.setSentDate(new Date());
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(messageText + ResourceBundle.getBundle("Bundle", locale).getString("notification.email.closing"));
try {
Transport.send(msg);
sent = true;
} catch (SMTPSendFailedException ssfe) {
logger.warning("Failed to send mail to " + to + " (SMTPSendFailedException)");
}
} else {
// commenting out the warning so as not to clutter the log of installations that haven't set up mail
// logger.warning("Skipping sending mail to " + to + ", because the \"no-reply\" address not set.");
}
} catch (AddressException ae) {
logger.warning("Failed to send mail to " + to);
ae.printStackTrace(System.out);
} catch (MessagingException me) {
logger.warning("Failed to send mail to " + to);
me.printStackTrace(System.out);
}
return sent;
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:34,代碼來源:MailServiceBean.java
示例5: Group
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
Group(String[] addr) {
this.recipients = new Address[addr.length];
for (int i = 0; i < addr.length; i++) {
try {
this.recipients[i] = new InternetAddress(addr[i]);
} catch (AddressException e) {
e.printStackTrace();
}
}
}
示例6: isValidEmailAddress
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
public static boolean isValidEmailAddress(String email) {
boolean result = true;
try {
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
} catch (AddressException ex) {
ex.printStackTrace();
result = false;
}
return result;
}
示例7: getInternetAddress
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
public InternetAddress getInternetAddress(){
try{
return new InternetAddress(this.getUsername() + "@" + this.getHost());
}catch(AddressException e){
e.printStackTrace();
return null;
}
}
示例8: setUp
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
@Before
public void setUp() {
try {
address = new InternetAddress("[email protected]");
} catch (AddressException e) {
e.printStackTrace();
}
assertNotNull(address);
subject = "test message";
body = "this is a test message body";
}
示例9: sendFromGMail
import javax.mail.internet.AddressException; //導入方法依賴的package包/類
private static Boolean sendFromGMail(String from, String pass, String[] to, String subject, String body) {
Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for( int i = 0; i < to.length; i++ ) {
toAddress[i] = new InternetAddress(to[i]);
}
for( int i = 0; i < toAddress.length; i++) {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
}
catch (AddressException ae) {
ae.printStackTrace();
}
catch (MessagingException me) {
me.printStackTrace();
}
return false;
}