使用 telnet 发送带有 shell 的电子邮件 我收到坏标志错误

Send email with shell with telnet I am receiving bad-flag error

我有自己的服务器,接收telnet邮件。我需要测试功能。我正在使用 expect shell 脚本。一切正常,直到我想尝试多部分消息。

我尝试在多部分边界定义中添加引号、删除空格、取消转义、组合。

#!/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 "--'boundary-string'": must be -i, -h, -s, -null, -0, -raw, -break, > or -

正确答案是

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"