Chinaunix

标题: 如何通过shell实现SMTP认证自动发送邮件!谢谢! [打印本页]

作者: stshen    时间: 2006-05-26 15:56
标题: 如何通过shell实现SMTP认证自动发送邮件!谢谢!
可以通过命令实现:如下:
telnet mail.domain 25
HELO mydomain
MAIL FROM:user@domain.com
RCPT TO:username@domain.com
DATA
.
QUIT
如何写成shell脚本定时发送
谢谢!
作者: cuci    时间: 2006-05-27 00:36
expect写个shell,然后crontab就是了
作者: 4Aiur    时间: 2006-05-28 14:51
请问如果发送的内容不是固定的怎么处理?
作者: 4Aiur    时间: 2006-05-28 17:14
不会使用expect的变量,用了一个笨方法做
a.sh
#!/bin/sh
cat a.exp >b.exp
echo send \"`cat temp`\\r\" >> b.exp
echo send \"\.\\r\" >> b.exp
echo expect eof >> b.exp
expect b.exp

$cat a.exp
spawn telnet 127.0.0.1 25
expect "*"
send "HELO test.com\r"
expect "*"
send "MAIL FROM:test@test.com\r"
expect "*"
send "RCPT TO:test@test.com\r"
expect "*"
send "RCPT TO:temp@temp.com\r"
expect "*"
send "DATA\r"
expect "*"
send "From: test@test.com\r"
expect "*"
send "To: test@test.com\r"
expect "*"
send "Subject: This is a test mail\r"
expect "*"
send "Mime-Version: 1.0\r"
expect "*"
send "Content-Type: text/plain\r"
expect "*"
send "Content-Transfer-Encoding: 7bit\r"
expect "*"
send "\r"
expect "*"
send "20060528\r"
expect "*"
作者: stshen    时间: 2006-05-29 11:51
标题: 带附件怎么处理呀!谢谢
#!/usr/bin/expect -f
spawn telnet Mail_server 25
expect "*"
send "HELO domain.com\r"
expect "*"
send "MAIL FROM:user@domain.com\r"
expect "*"
send "RCPT TO:user@domain.com\r"
expect "*"
send "DATA\r"
expect "*"
send ".\r"
expect "*"
send "QUIT\r"
作者: 4Aiur    时间: 2006-05-29 15:46
原帖由 stshen 于 2006-5-29 11:51 发表
#!/usr/bin/expect -f
spawn telnet Mail_server 25
expect "*"
send "HELO domain.com\r"
expect "*"
send "MAIL FROM:user@domain.com\r"
expect "*" ...

你这个没有发送变化的邮件内容




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2