Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
34
Task/Send-email/Scala/send-email.scala
Normal file
34
Task/Send-email/Scala/send-email.scala
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import java.util.Properties
|
||||
|
||||
import javax.mail.internet.{ InternetAddress, MimeMessage }
|
||||
import javax.mail.Message.RecipientType
|
||||
import javax.mail.{ Session, Transport }
|
||||
|
||||
/** Mail constructor.
|
||||
* @constructor Mail
|
||||
* @param host Host
|
||||
*/
|
||||
class Mail(host: String) {
|
||||
val session = Session.getDefaultInstance(new Properties() { put("mail.smtp.host", host) })
|
||||
|
||||
/** Send email message.
|
||||
*
|
||||
* @param from From
|
||||
* @param tos Recipients
|
||||
* @param ccs CC Recipients
|
||||
* @param subject Subject
|
||||
* @param text Text
|
||||
* @throws MessagingException
|
||||
*/
|
||||
def send(from: String, tos: List[String], ccs: List[String], subject: String, text: String) {
|
||||
val message = new MimeMessage(session)
|
||||
message.setFrom(new InternetAddress(from))
|
||||
for (to <- tos)
|
||||
message.addRecipient(RecipientType.TO, new InternetAddress(to))
|
||||
for (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