Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
3,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.60 KB | None | 0 0
  1. import java.io.File
  2. import java.net.Socket
  3. import java.util.*
  4.  
  5. fun main() {
  6.     println("Destination mail: ")
  7.     val destination = readLine()
  8.     println("Subject:")
  9.     val subject = readLine()
  10.     println("Mail content: ")
  11.     val mail = readLine()
  12.     println("Attachment file: ")
  13.     val filename = readLine()!!
  14.     val file = File(filename)
  15.     val content = Base64.getEncoder().encodeToString(file.readBytes())
  16.  
  17.     val boundary = UUID.randomUUID().toString().replace("-", "")
  18.  
  19.     val commands = listOf(
  20.             "EHLO sendmail",
  21.             "AUTH LOGIN",
  22.             "TUTAJ LOGIN",
  23.             "TUTAJ HASŁO",
  24.             "MAIL FROM: <aaaaaaaa.aaaaaa@interia.pl>",
  25.             "RCPT TO: <$destination>",
  26.             "DATA",
  27.  
  28.             """Subject: $subject
  29. From: aaaaaaaa.aaaaaa@interia.pl
  30. To: $destination
  31. MIME-Version: 1.0
  32. Content-Type: multipart/mixed; boundary="$boundary"
  33. """,
  34.             """--$boundary
  35. Content-Type: text/plain
  36.  
  37. $mail
  38. """,
  39.             """--$boundary
  40. Content-Type: application/octet-stream; name="${file.name}"
  41. Content-Disposition: attachment; filename="${file.name}"
  42. Content-Transfer-Encoding: base64
  43.  
  44. $content
  45.  
  46. --$boundary--
  47.  
  48.  
  49. .""",
  50.             "QUIT"
  51.     )
  52.  
  53.     Socket("poczta.interia.pl", 587).use {
  54.         val inputStream = it.getInputStream()
  55.         it.getOutputStream()
  56.                 .bufferedWriter()
  57.                 .apply {
  58.                     commands.forEach { command ->
  59.                         write(command)
  60.                         newLine()
  61.                         flush()
  62.                     }
  63.                 }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement