Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File
- import java.net.Socket
- import java.util.*
- fun main() {
- println("Destination mail: ")
- val destination = readLine()
- println("Subject:")
- val subject = readLine()
- println("Mail content: ")
- val mail = readLine()
- println("Attachment file: ")
- val filename = readLine()!!
- val file = File(filename)
- val content = Base64.getEncoder().encodeToString(file.readBytes())
- val boundary = UUID.randomUUID().toString().replace("-", "")
- val commands = listOf(
- "EHLO sendmail",
- "AUTH LOGIN",
- "TUTAJ LOGIN",
- "TUTAJ HASŁO",
- "MAIL FROM: <aaaaaaaa.aaaaaa@interia.pl>",
- "RCPT TO: <$destination>",
- "DATA",
- """Subject: $subject
- From: aaaaaaaa.aaaaaa@interia.pl
- To: $destination
- MIME-Version: 1.0
- Content-Type: multipart/mixed; boundary="$boundary"
- """,
- """--$boundary
- Content-Type: text/plain
- $mail
- """,
- """--$boundary
- Content-Type: application/octet-stream; name="${file.name}"
- Content-Disposition: attachment; filename="${file.name}"
- Content-Transfer-Encoding: base64
- $content
- --$boundary--
- .""",
- "QUIT"
- )
- Socket("poczta.interia.pl", 587).use {
- val inputStream = it.getInputStream()
- it.getOutputStream()
- .bufferedWriter()
- .apply {
- commands.forEach { command ->
- write(command)
- newLine()
- flush()
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement