use of javax.mail.internet.AddressException in project openolat by klemens.
the class MailManagerImpl method createAddress.
private Address createAddress(Identity recipient, MailerResult result, boolean error) {
if (recipient != null) {
if (recipient.getStatus() == Identity.STATUS_LOGIN_DENIED) {
result.addFailedIdentites(recipient);
} else {
String emailAddress = recipient.getUser().getProperty(UserConstants.EMAIL, null);
if (!StringHelper.containsNonWhitespace(emailAddress))
return null;
Address address;
try {
address = createAddress(emailAddress);
if (address == null) {
result.addFailedIdentites(recipient);
if (error) {
result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR);
}
}
return address;
} catch (AddressException e) {
result.addFailedIdentites(recipient);
if (error) {
result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR);
}
}
}
}
return null;
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class AccountUtil method generateMimeMessage.
public static MimeMessage generateMimeMessage(Account authAccount, Account ownerAccount, String subject, String charset, Collection<String> internalRecipients, String externalRecipient, String recipient, MimeMultipart mmp) throws MessagingException {
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(authAccount));
mm.setSubject(subject, CharsetUtil.checkCharset(subject, charset));
mm.setSentDate(new Date());
// from the owner
mm.setFrom(AccountUtil.getFriendlyEmailAddress(ownerAccount));
// sent by auth account
mm.setSender(AccountUtil.getFriendlyEmailAddress(authAccount));
if (internalRecipients != null) {
assert (externalRecipient == null);
for (String iRecipient : internalRecipients) {
try {
mm.addRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(iRecipient));
} catch (AddressException e) {
ZimbraLog.account.warn("Ignoring error while sending notification to " + iRecipient, e);
}
}
} else if (externalRecipient != null) {
mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(externalRecipient));
} else {
mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(recipient));
}
mm.setContent(mmp);
mm.saveChanges();
if (ZimbraLog.account.isDebugEnabled()) {
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
mm.writeTo(buf);
String mmDump = new String(buf.toByteArray());
ZimbraLog.account.debug("********\n" + mmDump);
} catch (MessagingException e) {
ZimbraLog.account.debug("failed log debug share notification message", e);
} catch (IOException e) {
ZimbraLog.account.debug("failed log debug share notification message", e);
}
}
return mm;
}
use of javax.mail.internet.AddressException in project che by eclipse.
the class GitHubOAuthAuthenticator method getUser.
@Override
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
GitHubUser user = getJson("https://api.github.com/user?access_token=" + accessToken.getToken(), GitHubUser.class);
GithubEmail[] result = getJson2("https://api.github.com/user/emails?access_token=" + accessToken.getToken(), GithubEmail[].class, null);
GithubEmail verifiedEmail = null;
for (GithubEmail email : result) {
if (email.isPrimary() && email.isVerified()) {
verifiedEmail = email;
break;
}
}
if (verifiedEmail == null || verifiedEmail.getEmail() == null || verifiedEmail.getEmail().isEmpty()) {
throw new OAuthAuthenticationException("Sorry, we failed to find any verified emails associated with your GitHub account." + " Please, verify at least one email in your GitHub account and try to connect with GitHub again.");
}
user.setEmail(verifiedEmail.getEmail());
final String email = user.getEmail();
try {
new InternetAddress(email).validate();
} catch (AddressException e) {
throw new OAuthAuthenticationException(e.getMessage());
}
return user;
}
use of javax.mail.internet.AddressException in project openhab1-addons by openhab.
the class CiscoSpark method sparkPerson.
/**
* Sends a Message to a Person via Cisco Spark
*
* @param msgTxt the Message to send
* @param personEmail the email of the person to which to send
*
* @return <code>true</code>, if sending the message has been successful and
* <code>false</code> in all other cases.
*/
@ActionDoc(text = "Sends a Message via Cisco Spark", returns = "<code>true</code>, if sending the tweet has been successful and <code>false</code> in all other cases.")
public static boolean sparkPerson(@ParamDoc(name = "msgTxt", text = "the Message to send") String msgTxt, @ParamDoc(name = "personEmail", text = "the email of the person to which to send") String personEmail) {
if (!CiscoSparkActionService.isProperlyConfigured) {
logger.warn("Cisco Spark is not yet configured > execution aborted!");
return false;
}
// Validate message
if (msgTxt == null || "".equals(msgTxt)) {
logger.warn("Message can't be empty");
return false;
}
// Validate email
try {
InternetAddress email = new InternetAddress(personEmail);
email.validate();
} catch (AddressException e) {
logger.warn("Email address is not valid");
return false;
}
try {
logger.debug("Creating message");
// Create the message
Message msg = new Message();
msg.setToPersonEmail(personEmail);
msg.setMarkdown(msgTxt);
logger.debug("About to send message");
// send the Message
spark.messages().post(msg);
logger.debug("Successfully sent Message '{}'", msg.getMarkdown());
return true;
} catch (SparkException se) {
logger.warn("Failed to send message.", se);
return false;
} catch (Exception e) {
logger.warn("Failed to send message!", e);
return false;
}
}
use of javax.mail.internet.AddressException in project nhin-d by DirectProject.
the class MessageServiceImplService method sendMessage.
@Override
public /**
* Converts an incoming WS request into an email message and sends it to the configured
* email server
*/
SendResponseType sendMessage(EmailType body) {
if (log.isDebugEnabled())
log.debug("Enter");
SendResponseType response = new SendResponseType();
checkAuth(response);
if (response.getError() == null) {
log.info("Auth success");
Multipart mailBody;
MimeBodyPart mainBody;
MimeBodyPart mimeAttach;
String fromaddress = body.getHead().getFrom().getAddress();
log.info("Got FROM address");
try {
InternetAddress addressFrom;
addressFrom = new InternetAddress(fromaddress.toString());
if (log.isDebugEnabled())
log.debug("Sender: " + addressFrom);
InternetAddress[] addressTo = new InternetAddress[1];
int i = 0;
for (AddressType recipient : body.getHead().getTo()) {
addressTo[i] = new InternetAddress(recipient.getAddress());
if (log.isDebugEnabled())
log.debug("Recipient: " + addressTo[i]);
i++;
}
Session session = Session.getInstance(smtpProps, new SMTPAuthenticator());
// Build message object
MimeMessage mimeMsg = new MimeMessage(session);
mimeMsg.setFrom(addressFrom);
mimeMsg.setRecipients(Message.RecipientType.TO, addressTo);
if (body.getHead().getSubject() != null) {
mimeMsg.setSubject(body.getHead().getSubject());
} else {
mimeMsg.setSubject("Direct message");
}
mailBody = new MimeMultipart();
mainBody = new MimeBodyPart();
if (body.getBody().getText() != null) {
mainBody.setText(body.getBody().getText());
} else {
mainBody.setText("");
}
mailBody.addBodyPart(mainBody);
copyAttachments(body, mailBody);
mimeMsg.setContent(mailBody);
DirectMimeMessage dMsg = new DirectMimeMessage(mimeMsg, getSenderHost());
dMsg.updateMessageID();
Transport transport;
if (getUseTLSforSMTP().equals("SOCKET")) {
transport = session.getTransport("smtps");
} else {
transport = session.getTransport("smtp");
}
transport.connect();
try {
transport.sendMessage(dMsg, addressTo);
// Transport.send(dMsg);
response.setMessageID(dMsg.getMessageID());
transport.close();
} finally {
transport.close();
}
} catch (AddressException e) {
ErrorType et = new ErrorType();
et.setCode(ErrorCodeType.ADDRESSING);
et.setMessage(e.getMessage());
response.setError(et);
log.error(e);
} catch (MessagingException e) {
ErrorType et = new ErrorType();
et.setCode(ErrorCodeType.MESSAGING);
et.setMessage(e.getMessage());
response.setError(et);
log.error(e);
} catch (Exception e) {
ErrorType et = new ErrorType();
et.setCode(ErrorCodeType.SYSTEM);
et.setMessage(e.getMessage());
response.setError(et);
log.error(e);
e.printStackTrace();
}
}
return response;
}
Aggregations