python通过smtplib链接到smtp.163.com可以正常发送,换perl就不行了。很诡异的事件啊。
perl程序大致代码如下:
use Net::SMTP;
$smtp = Net::SMTP->new('smtp.163.com', Hello => 'smtp.163.com' , Timeout => 120, Debug => 1);
$smtp->auth('xx@163.com','xx') or die("-- $!");
# 部分代码省略,具体可以看perldoc Net::SMTP
换了几个测试环境都不通过,显示认证失败,还有命令错误。很灵异的是同样的代码在别人机器就可以正常使用,我的就不行不论是win还是linux,估计是perl版本问题。折腾的有点崩溃。而且perl里MIME::Base64里的base64函数之后会多加一个/n。
最后很邪恶的实现了,用的系统expect。
$ chmod a+x aa.ex
$ ./aa.ex stmp.163.com base64之后的用户名 base64之后的密码 frommail tomail title content
aa.ex脚本如下:
#!/usr/bin/expect
set smtp [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set from [lindex $argv 3]
set to [lindex $argv 4]
set title [lindex $argv 5]
set content [lindex $argv 6]
spawn telnet $smtp 25
expect "220"
send "helo root/r"
expect "250"
send "auth login/r"
expect "334"
send "$user/r"
expect "334"
send "$pass/r"
expect "235"
send "MAIL FROM: <$from>/r"
expect "250"
send "RCPT TO: <$to>/r"
expect "250"
send "DATA/r"
expect "354"
send "TO: $to/r"
send "FROM: $from/r"
send "SUBJECT: $title/r"
send "/r"
send "$content/r"
send "./r"
expect "250"
send "QUIT"
expect telnet 发送邮件
最新推荐文章于 2023-06-29 14:16:13 发布