Passing Special Characters into telnet Unix

2020-07-22 19:06发布

问题:

I use the following command to send SMS messages through SMS Adapters:

telnet localhost 0000 <<-EOF 
helo x
MAIL FROM: Test
RCPT TO: 447999999999
DATA

Test £1234
.
logout
quit
EOF

However when ever I get the Message through it will be in the format:

Test ?£1234

Appending the ? to the front of the £ symbol, I have tried investigating a few methods including MIME however not quite sure how they can be implemented.

Any ideas on how I can stop and allow the successful passthroughs of £

回答1:

Have you tried encoding the message first? You can do this using base64 in UTF-8 charset:- e.g. Convert: msg="£1234" To: msg="wqMxMjM0"

NOTE:Try testing encoding/decoding using the online converter - https://www.base64encode.org/

Once you have encoded your text you can send the message via telnet by adding the MIME details after the DATA command in telnet by specifying MIME types, example script below:-

telnet localhost 0000 <<-EOF 
helo x
MAIL FROM: Test
RCPT TO: 447999999999
DATA
Subject: Test
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64

${msg}
.
logout
quit
EOF

Hope that helps.



回答2:

In some installations, telnet is not 8-bit clean by default (It does not recognize 8-bit character encodings such as Unicode). In order to be able to send Unicode keystrokes to the remote host, you need to set telnet into "outbinary" mode. There are two ways to do this:

$ telnet -L <host>

and

$ telnet

telnet> set outbinary

telnet> open <host>

Source