本文整理了Java中javax.mail.Message.setFrom()
方法的一些代码示例,展示了Message.setFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setFrom()
方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:setFrom
[英]Set the "From" attribute in this Message. The value of this attribute is obtained from the property "mail.user". If this property is absent, the system property "user.name" is used.
[中]设置此消息中的“发件人”属性。此属性的值是从属性“mail.user”获得的。如果缺少此属性,则使用系统属性“user.name”。
代码示例来源:origin: stackoverflow.com
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("mail@companyxyz.com", "Company XYZ"));
代码示例来源:origin: stackoverflow.com
import javax.mail.*;
import javax.mail.internet.*;
// Set up the SMTP server.
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", "smtp.myisp.com");
Session session = Session.getDefaultInstance(props, null);
// Construct the message
String to = "you@you.com";
String from = "me@me.com";
String subject = "Hello";
Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText("Hi,\n\nHow are you?");
// Send the message.
Transport.send(msg);
} catch (MessagingException e) {
// Error.
}
代码示例来源:origin: javamelody/javamelody
final Message msg = new MimeMessage(getSession());
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setFrom(fromAddress);
if (highPriority) {
msg.setHeader("X-Priority", "1");
代码示例来源:origin: stackoverflow.com
message.setFrom(new InternetAddress("your_user_name@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to_email_address@domain.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
代码示例来源:origin: JpressProjects/jpress
private Message createMessage() {
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", "25");
if (useSSL) {
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.port", "465");
}
// error:javax.mail.MessagingException: 501 Syntax: HELO hostname
props.setProperty("mail.smtp.localhost", "127.0.0.1");
Session session = Session.getInstance(props, this);
Message message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(MimeUtility.encodeText(name) + "<" + name + ">"));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return message;
}
代码示例来源:origin: apache/nifi
@Override
public void notify(final NotificationContext context, final NotificationType notificationType, final String subject, final String messageText) throws NotificationFailedException {
final Properties properties = getMailProperties(context);
final Session mailSession = createMailSession(properties);
final Message message = new MimeMessage(mailSession);
try {
message.setFrom(InternetAddress.parse(context.getProperty(FROM).evaluateAttributeExpressions().getValue())[0]);
final InternetAddress[] toAddresses = toInetAddresses(context.getProperty(TO).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.TO, toAddresses);
final InternetAddress[] ccAddresses = toInetAddresses(context.getProperty(CC).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.CC, ccAddresses);
final InternetAddress[] bccAddresses = toInetAddresses(context.getProperty(BCC).evaluateAttributeExpressions().getValue());
message.setRecipients(RecipientType.BCC, bccAddresses);
message.setHeader("X-Mailer", context.getProperty(HEADER_XMAILER).evaluateAttributeExpressions().getValue());
message.setSubject(subject);
final String contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
message.setContent(messageText, contentType);
message.setSentDate(new Date());
Transport.send(message);
} catch (final ProcessException | MessagingException e) {
throw new NotificationFailedException("Failed to send E-mail Notification", e);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
addressTo[i] = new InternetAddress( strArrRecipients[i] );
msg.setSubject( (String) ArgList[3] );
msg.setContent( ArgList[4], "text/plain" );
Transport.send( msg );
代码示例来源:origin: SeanDragon/protools
message.setFrom(new InternetAddress(userMail));
ts.sendMessage(message, message.getAllRecipients());
} catch (MessagingException | UnsupportedEncodingException e) {
代码示例来源:origin: stackoverflow.com
Properties properties = System.getProperties();
properties.put("mail.smtp.host", server);
properties.put("mail.smtp.port", "" + port);
Session session = Session.getInstance(properties);
Transport transport = session.getTransport("smtp");
transport.connect(server, username, password);
for (int i = 0; i < count; i++) {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);
message.setSubject(subject + "JavaMail API");
message.setSentDate(new Date());
setHTMLContent(message);
message.saveChanges();
transport.sendMessage(message, address);
}
transport.close();
代码示例来源:origin: javaee-samples/javaee7-samples
message.setFrom(new InternetAddress(creds.getFrom()));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(creds.getTo()));
message.setSubject("Sending message using Programmatic JavaMail " + Calendar.getInstance().getTime());
message.setText("Java EE 7 is cool!");
代码示例来源:origin: IanDarwin/javasrc
public void setFrom(String sender) throws MessagingException {
// From Address - this should come from a Properties...
mesg.setFrom(new InternetAddress(sender));
}
代码示例来源:origin: opensourceBIM/BIMserver
message.setSubject(subject);
message.setRecipients(to, addressTo);
message.setContent(body, contentType);
message.setFrom(from);
代码示例来源:origin: aa112901/remusic
"remusiclog1");
Message mailMessage = new SMTPMessage(session);
Address from = new InternetAddress("remusic_log@163.com");
mailMessage.setFrom(from);
Address to = new InternetAddress("remusic_log@163.com");
mailMessage.setRecipient(Message.RecipientType.TO, to);
mailMessage.setSubject(title);
mailMessage.setSentDate(new Date());
mailMessage.setText(content);
代码示例来源:origin: stackoverflow.com
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("Company XYZ <mail@companyxyz.com>"));
代码示例来源:origin: stackoverflow.com
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] addresses = new InternetAddress[recipientaddresstoshowinmail];
message.setRecipients(Message.RecipientType.TO, addresses);
message.setSubject(subject);
message.setText(body);
InternetAddress[] toaddress = new InternetAddress[] {new InternetAddress(to)};
**Transport.send(message, actualtoaddress);**
代码示例来源:origin: pentaho/pentaho-kettle
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
addressTo[i] = new InternetAddress( strArrRecipients[i] );
msg.setSubject( (String) ArgList[3] );
msg.setContent( ArgList[4], "text/plain" );
Transport.send( msg );
代码示例来源:origin: stackoverflow.com
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("admin@example.com", "Example.com Admin"));
代码示例来源:origin: stackoverflow.com
try {
Properties props = System.getProperties();
props.put("mail.smtp.auth", "true");
Session mailSession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(compression);
msg.setText(body);
msg.setSentDate(new Date());
代码示例来源:origin: javaee-samples/javaee7-samples
message.setFrom(new InternetAddress(creds.getFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(creds.getTo()));
message.setSubject("Sending message using Annotated JavaMail "
+ Calendar.getInstance().getTime());
message.setText("Java EE 7 is cool!");
代码示例来源:origin: stackoverflow.com
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("xxxx@gmail.com", "xxxx"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("user@testdomain.com,"Mr. User"));
msg.setSubject("Test email from GAE/J development");
msg.setText("This is test:);
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
内容来源于网络,如有侵权,请联系作者删除!