tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
56
Task/Send-email/Java/send-email.java
Normal file
56
Task/Send-email/Java/send-email.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import java.util.Properties;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.Message.RecipientType;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
/**
|
||||
* Mail
|
||||
*/
|
||||
public class Mail
|
||||
{
|
||||
/**
|
||||
* Session
|
||||
*/
|
||||
protected Session session;
|
||||
|
||||
/**
|
||||
* Mail constructor.
|
||||
*
|
||||
* @param host Host
|
||||
*/
|
||||
public Mail(String host)
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
properties.put("mail.smtp.host", host);
|
||||
session = Session.getDefaultInstance(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send email message.
|
||||
*
|
||||
* @param from From
|
||||
* @param tos Recipients
|
||||
* @param ccs CC Recipients
|
||||
* @param subject Subject
|
||||
* @param text Text
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public void send(String from, String tos[], String ccs[], String subject,
|
||||
String text)
|
||||
throws MessagingException
|
||||
{
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(from));
|
||||
for (String to : tos)
|
||||
message.addRecipient(RecipientType.TO, new InternetAddress(to));
|
||||
for (String cc : ccs)
|
||||
message.addRecipient(RecipientType.TO, new InternetAddress(cc));
|
||||
message.setSubject(subject);
|
||||
message.setText(text);
|
||||
Transport.send(message);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue