Отправить письмо с оболочкой через telnet Я получаю ошибку плохого флага - PullRequest
1 голос
/ 27 сентября 2019

У меня есть свой собственный сервер, на который я получаю электронные письма telnet.И мне нужно проверить функциональность.Я использую сценарий ожидаемой оболочки.Все работает нормально, пока я не попытаюсь попробовать составные сообщения.

Я пытался добавить кавычки к определению составной границы, удалить пробелы, удалить его, комбинацию из него.

#!/usr/bin/expect
set timeout 20
set fileName "/mnt/d/attachment.txt"
set to [lindex $argv 0]
spawn telnet localhost 25252
expect "220*"
send "ehlo Einstein\r"
#expect "250-*"
#expect "250-*"
expect "250*"
send "mail from:<einstein@milkyway.net>\r"
expect "250*"
send "rcpt to:<$to>\r"
expect "250*"
send "data\r"
expect "345*"
send "from: <einstein@milkyway.net>\r"
send "to: <$to>\r"
send "Subject: expect test\r"
send "Mime-Version: 1.0;\r"
send "Content-Type: Content-Type: multipart/alternative; boundary=boundary-string\r"

send "--boundary-string \r"

send "Content-Type: text/html; charset=\"ISO-8859-1\";\r"
send "Content-Transfer-Encoding: 7bit;\r"

send "\r"
send "<html>\r"
send "<body>\r"
send "<h1>This is HTML</h1> \r"
send "This is message with link <a href=\"http://www.google.sk\">Google</a> <img src=\"https://hips.hearstapps.com/ame-prod-menshealth-assets.s3.amazonaws.com/main/thumbs/34458/arnie-2.jpg?resize=768:*\" /> \r"
send "</body>\r"
send "</html>\r"

send "--boundary-string \r"
send "Content-Transfer-Encoding: base64\r"
send "Content-Disposition: attachment;filename=$fileName\r"
send "--boundary-string-- \r"

send ".\r"
expect "250*"
send "Quit"

Я получаюэта ошибка:

bad flag "- 'border-string'": должно быть -i, -h, -s, -null, -0, -raw, -break,> или -

1 Ответ

1 голос
/ 27 сентября 2019

Правильный ответ:

send - "--boundary-string \ r"

Я пробовал раньше всех остальных, кроме этого

Вот правильное и рабочее решение, которого я нигде не нашел:

#!/usr/bin/expect
set timeout 20
set separator "multikulti"
set to [lindex $argv 0]
spawn telnet localhost 25252
expect "220*"
send "ehlo Einstein\r"
expect "250*"
send "mail from:<einstein@milkyway.net>\r"
expect "250*"
send "rcpt to:<$to>\r"
expect "250*"
send "data\r"
expect "345*"
send "from: <einstein@milkyway.net>\r"
send "to: <$to>\r"
send "Subject: expect test\r"
send "Mime-Version: 1.0;\r"
send "Content-Type: multipart/mixed; boundary=$separator1\r"

send "This is just text \r\n"
send -- "--$separator1\r"
send "Content-Type: text/plain; charset=us-ascii\r"
send "This is plain text \r\n"

send -- "--$separator1 \r"
send "Content-Type: text/html; charset=ISO-8859-1\r\n"
send "<html>\r"
send "<body>\r"
send "<br /><h1>This is HTML</h1> \r"
send "<br /><br /><br /><br /><br clear=\"all\" /><img src=\"cid:0123456789\" width=\"400\" height=\"800\"/> \r"
send "<br /><br /><br /><br /><br clear=\"all\" /> \r"

send "This is message with link <a href=\"http://www.google.sk\">Google</a> <img src=\"https://hips.hearstapps.com/ame-prod-menshealth-assets.s3.amazonaws.com/main/thumbs/34458/arnie-2.jpg?resize=768:*\" /> \r"
send "</body>\r"
send "</html>\r\n"
send -- "--$separator1 \r"

send "Content-Type: image/png; name=\"abc.png\"\r"
send "Content-Disposition: attachment; filename=\"abc.png\"\r"
send "Content-Transfer-Encoding: base64\r"
send "Content-Location: abc.png\r\n"
send -- "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAADAFBMVEVHcEz////////////////////////////////////////////////////////////////////////////////////////////////////R590L8qdH0IYUsPvGuT9oYUfX63nBt4p9kkgx7X73OW3dnQzf30oYVgtSOhe5nmyelcbN9AauTcCOQ7b7nPfXCju/oMxE6cRBlZ4aGSPUtemfVfz7QzLYxBwuLKvfXT596U9yrGXzBtGGFzh9yQM6sGg5Pq7rfV2hmbt1AAVFpsdLlv2tddvfvn3pp5VwylhgYQvaM5sv15qnk/uLz9eu6eIZWiOtfPdzuWgKP6nLpttq8362ct//uCV5l7O2fGPXB5M+IpSRyzttfB7w97SV8qvlNVW1VeQTpajacYtNxAnldWWf/Pz57/49LnzvVeg3x01h/ApjR6fEN1nAfyGwpPtx66/UnPpdHl5+ZlL+14421HcVND36Ur+g9NGEr6nkLgUfyXOC5gZNCeD8E1lTF+RMkim9VGhgYQvK2Pt6hmjJBofnZK5wLethz6T2KDBfpjGJ6cnhqUGELeMAibfvyJyajKS7f5j1gdNDAkmbj0FhsTGzf7RpL4bQ/SYlPkrJq6NJ25pBU6eHjtvRMSiyPUp6TOnTpo0Mz3mhzOSor6fNn7cqvgA4v+Thk4LDh42LHja0HDClClTpkyZMmXKlClTpkyZMmXKlClTpkxpon8B5BxRDUYHIKkAAAAASUVORK5CYII=\r\n"

send -- "--$separator1 \r"

send "Content-Type: image/png; name=\"sig.png\"\r"
send "Content-Disposition: inline; filename=\"sig.png\"\r"
send "Content-Transfer-Encoding: base64\r"
send "Content-ID: <0123456789>\r"
send "Content-Location: sig.png\r\n"

send -- "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAADAFBMVEVHcEz////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////lLSe6JSDlLCbkJR7mMiz//v374N+5IBvGSkbmLSfkJB64JSC6JB/kJyG6JiHudXHy19bkJh/fm5m3GxblKyW4HhjlKiS5Ih24HBflKSO5JB/hLCbBJiHkLSf//Pz++vn+9/f......HIKkAAAAASUVORK5CYII=\r\n"
send -- "--$separator1--\r"

send ".\r"
expect "250*"
send "Quit"
...