本文整理汇总了Java中javax.mail.Transport.send方法的典型用法代码示例。如果您正苦于以下问题:Java Transport.send方法的具体用法?Java Transport.send怎么用?Java Transport.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Transport
的用法示例。
在下文中一共展示了Transport.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendCode
import javax.mail.Transport; //导入方法依赖的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";
}
示例2: sendMail
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* Sends an email.
*
* @param from
* The Email-address from the sender of this mail.
* @param to
* The Email-address of the receiver of this mail.
* @param subject
* The subject of the mail.
* @param body
* The content of the mail.
* @throws MailSendingException
* When sending the mail failed.
*/
public void sendMail(final String from, final String to, final String subject, final String body)
throws MailSendingException {
final MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSentDate(new Date());
message.setSubject(subject);
message.setText(body);
Transport.send(message);
} catch (final MessagingException e) {
throw new MailSendingException("Sending an email failed.", e);
}
}
示例3: errorOnSend
import javax.mail.Transport; //导入方法依赖的package包/类
@Test( expected = MailReportSendException.class)
public void errorOnSend() throws MessagingException {
mockStatic(Transport.class);
expect(ReportConfigurator.getInstance()).andReturn(mockReportConfigurator);
expect(mockReportConfigurator.getSmtpServerName()).andReturn("localhost");
expect(mockReportConfigurator.getSmtpServerPort()).andReturn("25");
expect(mockReportConfigurator.getAddressesTo()).andReturn(new String[]{ "userTo" });
expect(mockReportConfigurator.getAddressesCc()).andReturn(new String[0]);
expect(mockReportConfigurator.getAddressesBcc()).andReturn(new String[0]);
expect(mockReportConfigurator.getAddressFrom()).andReturn("userFrom");
Transport.send(isA(Message.class));
expectLastCall().andThrow(new MessagingException());
replayAll();
triggerRun();
verifyAll();
}
示例4: sendAttachMail
import javax.mail.Transport; //导入方法依赖的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;
}
}
示例5: sendAccountActivateEmail
import javax.mail.Transport; //导入方法依赖的package包/类
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
Session session;
try {
session = getSession();
MimeMessage message = new MimeMessage(session);
message.setSubject("������֤��");
message.setSentDate(new Date());
message.setFrom(new InternetAddress(FROM));
message.setRecipient(RecipientType.TO, new InternetAddress(email));
message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
"text/html;charset=utf-8");
message.saveChanges();
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: sendEmail
import javax.mail.Transport; //导入方法依赖的package包/类
private Boolean sendEmail(String randomKey, UserEntity userEntity) {
try {
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(Config.getEmailFrom()));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(userEntity.getEmail()));
message.setSubject("Recovery Password Email");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Dear user,\n\n");
stringBuilder.append("Someone requested to recover forgotten password in our soapbox race world server.\n\n");
stringBuilder.append("If wasn't you, just ignore this email.\n\n");
stringBuilder.append("You can click this link to reset your password:\n\n");
stringBuilder.append(Config.getServerAddress());
stringBuilder.append("/soapbox-race-core/password.jsp?randomKey=");
stringBuilder.append(randomKey);
stringBuilder.append("\n\nThanks for playing!\n\n");
stringBuilder.append("\n\nSBRW Team.\n");
message.setText(stringBuilder.toString());
Transport.send(message);
return true;
} catch (MessagingException mex) {
mex.printStackTrace();
return false;
}
}
示例7: send
import javax.mail.Transport; //导入方法依赖的package包/类
public void send(String toEmail) {
final String username = "[email protected]";
final String password = "mirapuru1";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(toEmail));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
} finally {
if (session != null) {
//TODO how to close?
}
}
}
示例8: sendMail
import javax.mail.Transport; //导入方法依赖的package包/类
/**
* Sends email.
*
* @throws MessagingException
* message exception
*/
private void sendMail() throws MessagingException {
/*
* Properties used to construct a email sending connection protocal.
*/
final Properties props = new Properties();
props.put("mail.smtp.host", MAIL_HOST);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
final Authenticator auth = new SMTPAuthenticator();
final MimeMessage msg = new MimeMessage(Session.getDefaultInstance(props, auth));
msg.setFrom(new InternetAddress(from));
msg.setRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(message);
Transport.send(msg);
}
示例9: sendMail
import javax.mail.Transport; //导入方法依赖的package包/类
public static void sendMail(String recipient, String subject, String body) {
try {
mimeMessage.setFrom(new InternetAddress(SENDER_ID + "@naver.com"));
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
mimeMessage.setSubject(subject);
mimeMessage.setText(body);
Transport.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例10: onNext
import javax.mail.Transport; //导入方法依赖的package包/类
@Override
public void onNext(T message) {
try {
Address[] addresses = new Address[]{new InternetAddress(destination)};
Transport.send(convertTo(message), addresses);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
subscription.request(1);
}
}
示例11: enviarMail
import javax.mail.Transport; //导入方法依赖的package包/类
public static void enviarMail(Persona cliente, String asunto, String mensaje) {
if (cliente.getPersonaMail() != null) {
Mail mail = obtenerMailEmisor();
Properties props = conectarse(mail);
Session session = autentificar(mail, props);
try {
BodyPart texto = new MimeBodyPart();
// Texto del mensaje
texto.setText(mensaje);
MimeMultipart multiParte = new MimeMultipart();
multiParte.addBodyPart(texto);
MimeMessage message = new MimeMessage(session);
// Se rellena el From
InternetAddress emisor = new InternetAddress(mail.getNombre() + " <" + mail.getMail() + ">");
message.setFrom(emisor);
// Se rellenan los destinatarios
InternetAddress receptor = new InternetAddress();
receptor.setAddress(cliente.getPersonaMail());
message.addRecipient(Message.RecipientType.TO, receptor);
// Se rellena el subject
message.setSubject(asunto);
// Se mete el texto y la foto adjunta.
message.setContent(multiParte);
Transport.send(message);
} catch (MessagingException e) {
messageService.informUser("Poliza creada, falló envío de mail");
}
}
}
示例12: sendMail
import javax.mail.Transport; //导入方法依赖的package包/类
public void sendMail(int uID, String URLlink, String Uname, String mailuser, String mailpass, String mailserver, String mailport, String mailsendadd, DB dbProperties) {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", mailserver);
props.put("mail.smtp.port", mailport);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailuser, mailpass);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(mailsendadd));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(ForgotDao.getEmail(uID, dbProperties)));
message.setSubject("Forgot your password!");
message.setContent("Dear "+Uname+", <BR><BR> Please click the following link to gain access to your account. <BR><BR> <a href=\""+URLlink+"\">Activate Account</a> <BR><BR> Thank You,", "text/html; charset=utf-8");
Transport.send(message);
System.out.println("Forgot Password E-mail Sent - "+ForgotDao.getEmail(uID, dbProperties));
} catch (MessagingException e) {
System.out.println("Error - Forgot Password E-mail Send FAILED - "+ForgotDao.getEmail(uID, dbProperties));
throw new RuntimeException(e);
}
}
示例13: sendTheEmail
import javax.mail.Transport; //导入方法依赖的package包/类
public void sendTheEmail() {
try {
Transport.send(message);
} catch (MessagingException e) {
loggingEngine.setMessage("Cannot send email! : " + e.getMessage());
}
}
示例14: send
import javax.mail.Transport; //导入方法依赖的package包/类
public void send(String email, String token) throws EmailException {
Properties properties = System.getProperties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", emailProperties.getSmtpHost());
properties.put("mail.smtp.port", emailProperties.getSmtpPort());
Session session = Session.getInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(emailProperties.getUsername(), emailProperties.getPassword());
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailProperties.getUsername()));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
message.setSubject(messages.getMessageBy("label.pathological.reports").concat(" - ").concat(messages.getMessageBy("label.recover.password")));
message.setText(createBody(emailProperties.getApplicationCtxPath(), token));
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
throw new EmailException(messages.getMessageBy("message.email.exception"));
}
}
示例15: sendAlert
import javax.mail.Transport; //导入方法依赖的package包/类
@Override
public void sendAlert(Observable observable) throws AddressException, MessagingException {
if (observable instanceof AbstarctMower) {
AbstarctMower mower = (AbstarctMower) observable;
ArrayList<MowerPosition> positionHistory = mower.getPositionHistory();
SettingInterface settingLoader = SettingLoaderFactory.getSettingLoader(DEFAULT);
Properties props = new Properties();
props.put("mail.smtp.host", settingLoader.getSMTPServer());
props.put("mail.smtp.socketFactory.port", String.valueOf(settingLoader.getSMTPPort()));
props.put("mail.smtp.socketFactory.class", settingLoader.getSSLSocketFactory());
props.put("mail.smtp.auth", settingLoader.isAuthenticationRequired());
props.put("mail.smtp.port", String.valueOf(settingLoader.getSMTPPort()));
String password = PasswordDecrypt.getInstance().decrypt("HA%HYDG1;[email protected]", "84m6BrC?T^P*!#bz",
settingLoader.getPassword());
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(settingLoader.getUserName(), password);
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(settingLoader.getSender()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(settingLoader.getUserName()));
String key0 = mower.getIdentifier();
String subject = MessageGetter.getMessage(EMAIL_ALERT_SUBJECT, new String[] { key0 });
message.setSubject(subject);
StringBuilder body = new StringBuilder();
for (int i = 1; i < positionHistory.size(); i++) {
MowerPosition mowerPosition = positionHistory.get(i);
body.append(mowerPosition.toString()).append(BR).append(BR);
}
String key1 = mower.getUpdateDate() != null ? mower.getUpdateDate().toString() : N_A;
String key2 = positionHistory.get(0) != null ? positionHistory.get(0).toString() : N_A;
String key3 = body.toString();
String bodyMessage = MessageGetter.getMessage(EMAIL_ALERT_MESSAGE, new String[] { key0, key1, key2, key3 });
message.setContent(bodyMessage, CONTENT_TYPE);
Transport.send(message);
}
}