Really trying to send the emails scala-emailer
authorJaroslav Tulach <jtulach@netbeans.org>
Thu, 26 Nov 2009 20:20:33 +0100
branchscala-emailer
changeset 154d9d5376d5f23
parent 153 ac818c32c6e9
child 155 388a3511c433
Really trying to send the emails
emailer/pom.xml
emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala
emailer/src/test/scala/cz/xelfi/quoridor/emailer/MainTest.scala
     1.1 --- a/emailer/pom.xml	Thu Nov 26 20:06:56 2009 +0100
     1.2 +++ b/emailer/pom.xml	Thu Nov 26 20:20:33 2009 +0100
     1.3 @@ -74,6 +74,11 @@
     1.4        <version>1.4.2</version>
     1.5      </dependency>
     1.6      -->
     1.7 +    <dependency>
     1.8 +      <groupId>javax.mail</groupId>
     1.9 +      <artifactId>mail</artifactId>
    1.10 +      <version>1.4.1</version>
    1.11 +    </dependency>
    1.12    </dependencies>
    1.13    <reporting>
    1.14      <plugins>
     2.1 --- a/emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala	Thu Nov 26 20:06:56 2009 +0100
     2.2 +++ b/emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala	Thu Nov 26 20:20:33 2009 +0100
     2.3 @@ -31,20 +31,37 @@
     2.4  import scala.io._
     2.5  import scala.collection.Map
     2.6  import scala.collection.mutable.HashMap
     2.7 +import javax.mail.internet._
     2.8 +import javax.mail.Message
     2.9 +import javax.mail.Transport
    2.10  
    2.11  object Main {
    2.12    def main(args: Array[String]) {
    2.13      val api = new URL("http://quoridor.xelfi.cz/api/");
    2.14  
    2.15      val id = login(api, "emailer", "otravuj")
    2.16 -    Console.println("id: " + id)
    2.17      
    2.18      val ret = allPlayers(
    2.19        api,
    2.20        3600 * 1000 * 24
    2.21      )
    2.22 +
    2.23 +    val props = java.lang.System.getProperties
    2.24 +    props.put("mail.smtp.host", "192.168.1.1");
    2.25 +
    2.26 +    val session = javax.mail.Session.getDefaultInstance(props, null)
    2.27 +
    2.28 +
    2.29      for (val address <- emails(api, id, ret.keySet)) {
    2.30 -        Console.println(address)
    2.31 +        Console.println("Sending message to " + address)
    2.32 +
    2.33 +        val message = new MimeMessage(session)
    2.34 +        message.setFrom(new InternetAddress("quoridor@xelfi.cz"))
    2.35 +        message.addRecipient(Message.RecipientType.TO, new InternetAddress(address))
    2.36 +        message.setSubject("Play Quoridor!")
    2.37 +        message.setText("Visit http://quoridor.xelfi.cz")
    2.38 +
    2.39 +        Transport.send(message)
    2.40      }
    2.41    }
    2.42  
     3.1 --- a/emailer/src/test/scala/cz/xelfi/quoridor/emailer/MainTest.scala	Thu Nov 26 20:06:56 2009 +0100
     3.2 +++ b/emailer/src/test/scala/cz/xelfi/quoridor/emailer/MainTest.scala	Thu Nov 26 20:20:33 2009 +0100
     3.3 @@ -7,7 +7,9 @@
     3.4  class AppTest {
     3.5  
     3.6      @Test
     3.7 -    def testOK() = assertTrue(true)
     3.8 +    def testCheckLazyPlayers() = {
     3.9 +      Main.main(null)
    3.10 +    }
    3.11  
    3.12  //    @Test
    3.13  //    def testKO() = assertTrue(false)