Scenario:
If you want to know if a smtp server would accept mail from your host. You can use sshscript to create a script to send a mail by connecting to the smtp server using the SMTP protocol.
file: mailtest.spy
import re, datetime
host = 'smtp.your.domain'
port = 25
mailfrom = 'you@your.domain'
mailto = 'she@her.domain'
subject = f'test at {datetime.datetime.now()}'
## uncomment the next line if you want to test on remote host.
#$.connect('username@remote_host')
## This script requires "telnet" to run.
## You can use an equivalent like "nc -v" by modifying the next line.
with $telnet @{host} @{port} as console:
console.expect(re.compile('.+')) # any response
console.sendline(f'helo')
console.sendline(f'mail from: {mailfrom}')
console.sendline(r'rcpt to: {mailto}')
console.sendline('data')
## wait longer, in care the smtp server responses slowly
console.expect('CRLF',180)
body = f'''subject: {subject}
from: {mailfrom}
have a nice day.
.
'''
if 1:
## for v1.1.17 or lower
console.sendline([body])
else:
## for v.1.1.18 and above
console.sendline(body,raw=1)
console.expect(re.compile('.+'))
console.sendline('quit')
Examples of execution command
$sshscript mailtest.spy
$sshscript mailtest.spy --verbose
$sshscript mailtest.spy --verbose --debug
Last Updated: 2026-07-25 16:59:40
Table of contents
- SSHScript v3.1 Documentation
- Accounts (legacy URL)
- Checking the syncing status of two MySQL servers
- Getting Started with SSHScript
- Page not found
- Q: What can it do that Netmiko doesn’t do? (origin)
- SSHScript Documentation
- SSHScript Documents
- SSHScript v2.0 CLI(Draft)
- SSHScript v2.0 Commands Execution and Console
- SSHScript v2.0 Console of sudo and su
- SSHScript v2.0 Getting Started
- SSHScript v2.0 Interactive Commands and Foreground Commands
- SSHScript v2.0 Make Connections
- SSHScript v2.0 Recipes
- SSHScript v2.0 Reference Guide
- SSHScript v2.0 Stdout, Stderr and Exitcode
- SSHScript v2.0 Threading Support
- SSHScript v2.0 Upload and Download Files
- SSHScript v2.0.2 Release Notes
- SSHScript v3.0 Interactive and Foreground Commands
- SSHScript v3.0 Reference Guide
- SSHScript v3.0.0 Release Notes
- SSHScript v3.1
- SSHScript vs. Ansible
- 用 Python 作系統自動化