當前位置: 首頁>>代碼示例>>Java>>正文


Java AddressException類代碼示例

本文整理匯總了Java中javax.mail.internet.AddressException的典型用法代碼示例。如果您正苦於以下問題:Java AddressException類的具體用法?Java AddressException怎麽用?Java AddressException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AddressException類屬於javax.mail.internet包,在下文中一共展示了AddressException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMail

import javax.mail.internet.AddressException; //導入依賴的package包/類
public static void sendMail(String host, int port, String username, String password, String recipients,
		String subject, String content, String from) throws AddressException, MessagingException {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.port", port);

	Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	});

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
	message.setSubject(subject);
	message.setText(content);

	Transport.send(message);
}
 
開發者ID:bndynet,項目名稱:web-framework-for-java,代碼行數:24,代碼來源:MailHelper.java

示例2: buildMessage

import javax.mail.internet.AddressException; //導入依賴的package包/類
private static Message buildMessage(Session session, String from, String recipients, String subject, String text, String filename) throws MessagingException, AddressException
{
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
    message.setSubject(subject);

    BodyPart messageTextPart = new MimeBodyPart();
    messageTextPart.setText(text);

    BodyPart messageAttachmentPart = new MimeBodyPart();
    DataSource source = new FileDataSource(new File(filename));
    messageAttachmentPart.setDataHandler(new DataHandler(source));
    messageAttachmentPart.setFileName(filename);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageTextPart);
    multipart.addBodyPart(messageAttachmentPart);
    message.setContent(multipart);

    return message;
}
 
開發者ID:marcelovca90,項目名稱:anti-spam-weka-gui,代碼行數:23,代碼來源:MailHelper.java

示例3: toAddresses

import javax.mail.internet.AddressException; //導入依賴的package包/類
/**
 * 
 * @param tos address String array
 * @return Address Array
 * @throws AddressException address convert exception
 */
protected Address[] toAddresses(final String tos) throws AddressException {
    if(tos != null && !"".equals(tos)) {
        final List<Address> to = Lists.newArrayList();
        final String[] toArray = tos.split(";");
        if(ArrayUtils.isNotEmpty(toArray)) {
            for(final String address : toArray) {
                if(StringUtils.isNotBlank(address)) {
                    to.add(new InternetAddress(address.trim()));
                }
            }
        }
        
        return to.toArray(new InternetAddress[0]);
    }
    
    return null;
}
 
開發者ID:nano-projects,項目名稱:nano-framework,代碼行數:24,代碼來源:AbstractMailSenderFactory.java

示例4: dispatchAnonymousMessage

import javax.mail.internet.AddressException; //導入依賴的package包/類
private void dispatchAnonymousMessage() throws AddressException, MessagingException {
	int sendDelay = this.config.getInt(ConfigKeys.MAIL_SMTP_DELAY);

	for (User user : this.users) {
		if (StringUtils.isEmpty(user.getEmail())) {
			continue;
		}

		if (this.needCustomization) {
			this.defineUserMessage(user);
		}

		Address address = new InternetAddress(user.getEmail());

		if (logger.isTraceEnabled()) {
			logger.trace("Sending mail to: " + user.getEmail());
		}

		this.message.setRecipient(Message.RecipientType.TO, address);
		Transport.send(this.message, new Address[] { address });

		if (sendDelay > 0) {
			this.waitUntilNextMessage(sendDelay);
		}
	}
}
 
開發者ID:eclipse123,項目名稱:JForum,代碼行數:27,代碼來源:Spammer.java

示例5: completeClientSend

import javax.mail.internet.AddressException; //導入依賴的package包/類
public void completeClientSend(String mailServer, String... credentials) throws AddressException, MessagingException {
	if (credentials != null && credentials.length > 1) {
		// Step1
		logger.info("\n 1st ===> setup Mail Server Properties..");
		logger.info("Mail Server Properties have been setup successfully..");
		// Step2
		logger.info("\n\n 2nd ===> get Mail .");
		getMailSession = getDefaultInstance(mailServerProperties, null);
		generateMailMessage = new MimeMessage(getMailSession);
		generateMailMessage.addRecipient(TO, new InternetAddress("[email protected]"));
		generateMailMessage.addRecipient(CC, new InternetAddress("[email protected]"));
		generateMailMessage.setSubject("Greetings from Vige..");
		String emailBody = "Test email by Vige.it JavaMail API example. " + "<br><br> Regards, <br>Vige Admin";
		generateMailMessage.setContent(emailBody, "text/html");
		logger.info("Mail Session has been created successfully..");
		// Step3
		logger.info("\n\n 3rd ===> Get Session and Send mail");
		Transport transport = getMailSession.getTransport("smtp");
		// Enter your correct gmail UserID and Password
		// if you have 2FA enabled then provide App Specific Password
		transport.connect(mailServer, credentials[0], credentials[1]);
		transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
		transport.close();
	}
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:26,代碼來源:SendMail.java

示例6: addUser

import javax.mail.internet.AddressException; //導入依賴的package包/類
/**
 * Adds a user email address (InternetAddress) to the list
 * @param userID
 * @param list
 * @throws AddressException
 */
private void addUser(final Integer userID, final List list) throws AddressException {

  if (userID == null) {
    return;
  }

  final User user = SecurityManager.getInstance().getUser(userID.intValue());
  if (user == null) {
    return;
  }

  final String startedEmail = user.getEmail();
  if (StringUtils.isBlank(startedEmail)) {
    return;
  }

  list.add(new InternetAddress(startedEmail));
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:EmailRecipientListComposer.java

示例7: javaMailSenderWithParseExceptionOnMimeMessagePreparator

import javax.mail.internet.AddressException; //導入依賴的package包/類
@Test
public void javaMailSenderWithParseExceptionOnMimeMessagePreparator() {
	MockJavaMailSender sender = new MockJavaMailSender();
	MimeMessagePreparator preparator = new MimeMessagePreparator() {
		@Override
		public void prepare(MimeMessage mimeMessage) throws MessagingException {
			mimeMessage.setFrom(new InternetAddress(""));
		}
	};
	try {
		sender.send(preparator);
	}
	catch (MailParseException ex) {
		// expected
		assertTrue(ex.getCause() instanceof AddressException);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:JavaMailSenderTests.java

示例8: send

import javax.mail.internet.AddressException; //導入依賴的package包/類
public static void send(String toStr, String subject,
		String body, boolean isHtml) throws SystemException, AddressException, PortalException {

	Company cmp = null;
	try {
	  cmp = CompanyServiceUtil.getCompanyByVirtualHost(AppConstants.COMPANY_VIRTUAL_HOST);
	} catch (Throwable t) {
		
	}
	if (cmp != null) {
		long cmpId = cmp.getCompanyId();
		String fromStr = PrefsPropsUtil.getString(cmpId,
				PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
		InternetAddress from = new InternetAddress(fromStr);
		InternetAddress to = new InternetAddress(toStr);
		if (from != null && to != null && subject != null && body != null) {
			MailMessage message = new MailMessage(from, to, subject, body, isHtml);
			MailServiceUtil.sendEmail(message);
		}
	}

}
 
開發者ID:fraunhoferfokus,項目名稱:govapps,代碼行數:23,代碼來源:MailUtil.java

示例9: buildEmailMessage

import javax.mail.internet.AddressException; //導入依賴的package包/類
private Message buildEmailMessage(EmailInfo emailInfo)
		throws AddressException, MessagingException, UnsupportedEncodingException {
	MimeMessage message = new MimeMessage(this.session);
	message.setFrom(new InternetAddress(emailInfo.getFrom(), "網頁更新訂閱係統", "UTF-8"));
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));

	Multipart multipart = new MimeMultipart();
	BodyPart messageBodyPart = new MimeBodyPart();
	messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
	multipart.addBodyPart(messageBodyPart);
	message.setContent(multipart);
	message.setSubject(emailInfo.getTitle());
	message.saveChanges();
	return message;
}
 
開發者ID:wrayzheng,項目名稱:webpage-update-subscribe,代碼行數:16,代碼來源:EmailServer.java

示例10: sendEmail

import javax.mail.internet.AddressException; //導入依賴的package包/類
private void sendEmail(TokenStoreEntity token, UserEntity user) {
	Map<String, Object> params = new HashMap<>();
	String subject;
	String template;
	if (TokenStoreType.USER_ACTIVATION.equals(token.getType())){
		params.put("activationUrl", baseUrl + "/registration/activate?at=" + token.getToken());
		subject = "Registration Confirmation";
		template = "email/registration.html";
	} else {
		params.put("changepassUrl", baseUrl + "/changepass/update?rt=" + token.getToken());
		subject = "Reset Password Confirmation";
		template = "email/changepass.html";
	}
	try {
		emailService.sendEmail(null, new InternetAddress(user.getEmail()), subject, params, template);
	} catch (AddressException e) {
		throw new RegistrationException("Unable to send activation link");
	}
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:20,代碼來源:TokenStoreServiceImpl.java

示例11: notify

import javax.mail.internet.AddressException; //導入依賴的package包/類
/**
 * This method is used to send slack and email notification.  
 * 
 * @param empSlackId slackId of employee
 * @param channelId channelId of Channel
 * @param Visitor visitor information
 * @param ndaFilePath path of nda file
 * 
 * @return boolean
 * @throws IOException 
 * @throws AddressException 
 */  
public boolean notify(String empSlackId, String channelId, Visitor visitor, String ndaFilePath) throws AddressException, IOException  {
	logger.info("Started sending slack/email notification.");
	Employee employee  = null;
	SlackChannel channel = null;
	String locationName = locationService.getLocationName(visitor.getLocation()).getLocationName();
	if (StringUtils.isNotBlank(empSlackId) && StringUtils.isBlank(channelId)) {
		employee = employeeService.getBySlackId(empSlackId);                          
	} else {
		channel = channelService.findByChannelId(channelId);
	}
	if (Objects.nonNull(visitor)) {
			notifyOnSlack(employee, visitor, channel, locationName);
			notifyOnEmail(employee, visitor, channel, ndaFilePath, locationName);
	}
	return true;
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:29,代碼來源:NotificationService.java

示例12: execute

import javax.mail.internet.AddressException; //導入依賴的package包/類
public void execute(SmtpConnection conn, SmtpState state,
                    SmtpManager manager, String commandLine) {
    Matcher m = param.matcher(commandLine);
    try {
        if (m.matches()) {
            String from = m.group(1);

            MailAddress fromAddr = new MailAddress(from);

            String err = manager.checkSender(state, fromAddr);
            if (err != null) {
                conn.println(err);

                return;
            }

            state.clearMessage();
            state.getMessage().setReturnPath(fromAddr);
            conn.println("250 OK");
        } else {
            conn.println("501 Required syntax: 'MAIL FROM:<[email protected]>'");
        }
    } catch (AddressException e) {
        conn.println("501 Malformed email address. Use form [email protected]");
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-greenmail,代碼行數:27,代碼來源:MailCommand.java

示例13: MailAddress

import javax.mail.internet.AddressException; //導入依賴的package包/類
public MailAddress(String str)
        throws AddressException {
    InternetAddress address = new InternetAddress(str);
    email = address.getAddress();
    name = address.getPersonal();

    String[] strs = email.split("@");
    user = strs[0];
    if (strs.length>1) {
        host = strs[1];
    } else {
        host = "localhost";
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-greenmail,代碼行數:15,代碼來源:MailAddress.java

示例14: validate

import javax.mail.internet.AddressException; //導入依賴的package包/類
/**
 * Performs a type-specific validation for the given
 * {@link ValidationType}
 */
@Override
public void validate() throws TypeException {

    try {
        super.validate();

    } catch (TypeException e) {
        throw new TypeException(ERROR_MESSAGE_INVALID_EMAIL + e.getMessage(), this.parameterName, e);
    }

    try {
        String email = (String) this.value;
        // Note that the JavaMail's implementation of email address validation is
        // somewhat limited. The Javadoc says "The current implementation checks many,
        // but not all, syntax rules.". For example, the address [email protected] is correctly
        // flagged as invalid, but the address "a"@ is considered
        // valid by JavaMail, even though it is not valid according to RFC 822.
        new InternetAddress(email, true);
    } catch (AddressException ae) {
        throw new TypeException(ERROR_MESSAGE_INVALID_EMAIL, this.parameterName, ae);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:TypeEmailAddress.java

示例15: validateEmailList

import javax.mail.internet.AddressException; //導入依賴的package包/類
public void validateEmailList(FacesContext context,
                              UIComponent  component,
                              Object       value) throws ValidatorException
{
  if (value == null)
    return;

  try
  {
    _getEmailList(value.toString());
  }
  catch (AddressException ae)
  {
    throw new ValidatorException(
     MessageUtils.getErrorMessage(context,
                                  "EMAIL_LIST_ERROR",
                                  new Object[]{ae.getRef()}));

  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:21,代碼來源:NewMessageBackingBean.java


注:本文中的javax.mail.internet.AddressException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。