导航:首页 > IDC知识 > smtp服务器的helo域名

smtp服务器的helo域名

发布时间:2020-10-23 22:11:26

1、重装系统后宽带连接错误553

您好,请检查一下本身服务器的HELO信息,后面是否是一个完整的域名,HELO信息如果不完整,也就无法给我们的邮箱发邮件。系统返回信息和服务器基本设置HELO信息帮助:
1.为什么新浪服务器会产生553的退信信息?
这是由于邮件发送方服务器的HELO域设置不规范造成的。如果新浪服务器无法对该域进行正确的DNS解析, 将会导致新浪反垃圾系统认为该服务器是垃圾邮件发送者从而拒收. 不规范的HELO域的示例如下:
HELO office
HELO mailserver
HELO localhost.localdomain
解决方法: 参考本文档后半部分提供的设置方法,正确设置贵方SMTP服务器的HELO域, 使新浪能过对该域名进行正确的DNS解析
2.SMTP服务器能否设置为公司内网的域名?
请设置贵公司的服务器对外发送的HELO域为正确的贵公司域名,否则将因为和第一条同样的原因造成新浪拒收。
3.SMTP服务器的HELO域已设置正确,怎么还产生553的退信信息?
这是由于发邮件服务器在内网的某个网段中。如果邮件经防火墙发送, 而防火墙没有对邮件的源IP地址进行映射, 新浪的服务器就会认为防火墙的IP是发件方SMTP服务器的IP地址,而邮件源IP地址与HELO域名MX解析不一致. 这种情况也会使新浪拒收邮件。解决方法: 使HELO后面的域名MX解析为防火墙的IP地址, 或者使防火墙把经过它的邮件的IP映射为其真正的IP地址, 即不要改变邮件的源IP地址.
4.SMTP服务器的HELO域能否包含特殊字符?
不可以。如果发邮件服务器的HELO域中包含有无法识别的字符, 就会导致新浪对其DNS解析失败, 从而拒绝接收其邮件.
包含有无法识别字符的HELO域示例: eev?bj?md02.vatech
5.国外网站应如何正确设置SMTP服务器?
新浪要求所有中国大陆境外的CMTP服务器必须提供反向DNS解析。对于中国境外的CMTP服务器,如果不提供反向DNS解析,新浪将认为该服务器为垃圾邮件发送者的服务器并拒收该地址发来的邮件。
解决方法: 注册SMTP服务器公网IP地址的RDNS服务, 并把它对应的域名写到服务器的HELO域中.
6.MS Exchange2000服务器HELO域的设置方法
具体位置在: SERVER---主名---SMTP---DEFAULT SMTP VIRTUAL---属性---DELIVERY---ADVANCED---MASQUERADE NAME
7.Notes服务器HELO域的设置方法
具体位置在:服务器---基本---全限定的Internet主机

2、什么是SMTP协议

 SMTP被用来在因特网上传递电子邮件。文件RFC821规定了该协议的所有细节。但是你只须记住下面的内容--该协议的基本命令和方法就行了。

协议的原理很简单。无非是一个客户端计算机向服务器发送命令,然后服务器向客户端计算机返回一些信息。客房端发送的命令以及服务器的回应都是字符串,你并不需要特别的软件就能读出它们。如果你仔细看过WinsockTerminal示例程序的源代码,你就会发现这一点。现在让我们用这个示例程序来向自己发一封电子邮件吧。

运行示例程序,单击"Connect"按钮,在"Connectto..."对话框中输入你的电子邮件服务器的地址,选择SMTP选项。最后按"Connect"按钮。如果连接成功,Winsock控件会产生Connected事件,在状态栏中也可看到连接成功的信息。在主文本窗口中你将看到从服务器返回的文本。该文本包含一个三位数的代码及描述,例如:

220-ns.cinfo.ruSendmail8.6.12/8.6.9readyatWed,22Apr199822:54:41+0300
220ESMTPspokenhere

不必太过留意这些描述。因为这些描述可能会因服务器而异。你只须要知道代码所代表的意思就行了。代码220表示成功建立连接,服务器等待你的第一个命令。

向服务器传递的第一个命令是HELO.该命令包含一个参数,即你的邮箱名。

HELOoleg

注意:在RFC821中,HELO是一个可选择性命令,如果服务器不要求该命令的话,你可以把它忽略掉。

如果命令成功,服务器会返回一个代码为250的回应。下一步用MAILFROM命令告诉服务器你想发一封邮件。该命令以发信人的邮件地址为参数。

MAILFROM:[email protected]

发完命令后,如果服务器返回一个代码为250回应,你就可以向服务器发送RCPTTO命令了。该命令以收信人地址为参数,一看便知是告诉服务器你想将邮件发到收信人地址处。

RCPTTO:[email protected]

如果你想将邮件发给多个收件人的话。你需要多次使用RCPTTO命令,对每个命令,服务器都会返回代码为250的回应。

现在你可以向服务器发送邮件正文了。用DATA命令告诉服务器以下的内容为邮件正文。在你从服务器收到代码为354的回应后,你就可以发送邮件正文了。邮件按行发送,每行邮件以一个无回车的换行符结束(在VB中就是vbLf)示例程序知道何时使用换行符,何时使用回车加换行符。所以你只须按回车键就行了。下面是一个例子:

Subject:Myfirste-mailmessage.

 Firstlineofamessage.
 Secondline.
 .

注意上面最后一行的最后一个字符是一个小数点。这是正文结束的标志。用VB代码表示就是vbLf&"."&vbCrLf.服务器收到这个标志后,就会立即向你返回一个代码为250的回应以及该邮件的唯一ID号。任务完成了,你可以继续发送下封邮件,也可以断开同服务器的连接。如果要断开同服务器的连接就用QUIT命令。在这种情况下,服务器会返回一个代码为221的回应并断开连接。

QUIT

3、怎么阻止HELO为某个域的SMTP连接

SECURITY】-【IP
SHIELDING】应该是不行的它只能限制发件人@后面的域名只能来自某个IP而现在它每次发件人的邮址都是来自不同的域名但它有个特点就是每次的HELO域名都不变

4、请问如何用python将某个邮箱未读邮件全部转发到另一个邮箱?

首先了解SMTP(简单邮件传输协议),邮件传送代理程序使用SMTP协议来发送电邮到接收者的邮件服务器。SMTP协议只能用来发送邮件,不能用来接收邮件,而大多数的邮件发送服务器都是使用SMTP协议。SMTP协议的默认TCP端口号是25。

本文主要介绍利用'smtplib','email'两个模块来实现邮件的发送,可以如下查看两个模块的函数和方法:

smtplib模块简介:

smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])
  此为SMTP类构造函数,表示与SMTP服务器之间的连接,并根据这个连接向smtp服务器发送指令,执行相关操作(如:登陆、发送邮件),且每个参数都是可选的。
其中最重要的参数:
host:smtp服务器主机名
port:smtp服务的端口,默认是25;
如果在创建SMTP对象的时候提供了这两个参数,在初始化的时候会自动调用connect方法去连接服务器。

smtplib.SMTP还提供了如下方法:
SMTP.set_debuglevel(level):设置是否为调试模式
SMTP.connect([host[, port]]):连接到指定的smtp服务器。参数分别表示 smpt主机和端口。
SMTP.docmd(cmd[, argstring]):向smtp服务器发送指令。
SMTP.helo([hostname]) :使用"helo"指令向服务器确认身份。
SMTP.login(user, password):登陆到smtp服务器。现在几乎所有smtp服务器,都必须在验证用户信息合法之后才允许发送邮件。(重要!)
SMTP.sendmail(from_addr,to_addrs,msg[,mail_options,rcpt_options]):发送邮件。这里要注意一下第三个参数,msg是字符串,表示邮件。我们知道邮件一般由标题,发信人,收件人,邮件内容,附件等构成,发送邮件的时候,要注意msg的格式。这个格式就是smtp协议中定义的格式。SMTP.quit() :断开与smtp服务器的连接,相当于发送"quit"指令。(重要!)

常用的函数方法:

email模块
1.class email.message.Message
__getitem__,__setitem__实现obj[key]形式的访问。
Msg.attach(playload): 向当前Msg添加playload。
Msg.set_playload(playload):
Msg.add_header(_name, _value, **_params): 添加邮件头字段。

2.class email.mime.base.MIMEBase(_maintype, _subtype, **_params)
所有MIME类的基类,是email.message.Message类的子类。

3.class email.mime.multipart.MIMEMultipart()
在3.0版本的email模块 (Python 2.3-Python 2.5) 中,这个类位于email.MIMEMultipart.MIMEMult ipart。这个类是MIMEBase的直接子类,用来生成包含多个部分的邮件体的MIME对象。

4.class email.mime.text.MIMEText(_text)
使用字符串_text来生成MIME对象的主体文本。

获得所需要使用的邮箱的host地址和port端口号,(本文使用的是163邮箱,对应的smtp服务器地址:mail.163.com,端口号25)
常用邮箱的smtp服务器地址和端口号如图:

编写程序如下:

#! /usr/bin/env python
import smtpli
from email.mime.text import MIMEText

mailto_list=['[email protected]'] #收件人(列表)
mail_host="smtp.163.com" #使用的邮箱的smtp服务器地址
mail_user="name" #用户名
mail_pass="pwd" #密码
mail_postfix="postfix" #邮箱的后缀
def send_mail(to_list,sub,content):
me="hello"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype='plain')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list) #将收件人列表以‘;’分隔
try:
server = smtplib.SMTP()
server.connect(mail_host) #连接服务器
server.login(mail_user,mail_pass) #登录操作
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
for i in range(5): #发送五封,不过会被拦截的。。。
if send_mail(mailto_list,"hello","haha!"): #邮件主题和邮件内容
print "done!"
else:
print "failed!"

最后,可以运行编写的py文件,可以得到如图所是的结果,代表邮件发送成功。

这样,就能成功实现用Python发送邮件啦!

5、我想用smtp发邮件,建立连接后发送"HELO sss"后,没有反应,用java写的程序,求救

你确定不需要使用用户名和密码?
你不如下个java的mail包(不包含在jdk在官网有),或者直接使用apache common的mail包试试

6、exchange2003如何拒绝HELO命令

我看出来,你想禁用SMTP VERBS,这需要修改ADSIEdit 在 Active Directory 中的 值。

要修改此值通过 ADSIEdit:
1.打开 ADSIEdit 并连接到域控制器。
2.打开配置容器。
3.导航到以下位置:
配置 / 服务 / Microsoft Exchange / < 您的组织 > / 管理组 / < 您的管理组 > /Servers/ < Exchange Server > / 协议 / SMTP < 您的虚拟服务器编号 >
4.右键单击该虚拟服务器对象,然后单击 属性 。
5.选择要查看的属性: 选择 。
6.在该 编辑属性: 字段中,输入要为其设置的值。

注意 : 此值基于表中的值汇总。
7.单击 设置 , 应用 ,然后单击 确定 。
8.退出 ADSIEdit。

我错了,这个我试了一下,并不能回复221.。。

7、PHP中发送邮件的代码!

从代码来看,想必楼主是想把表单提交的内容发送至指定邮箱,而这个邮箱地址也是在表单中填写的,$sendTo变量的值被赋为表单项“toMail”传过来的值。
如此,你可以在填写表单的时候在toMail表单项里填入“[email protected]”,或者直接$sendTo="[email protected]"。

接下来就要考虑是否能发送出去了:

1、如果楼主配置的服务器安装了sendmail组件,就可以直接使用你写的这段代码来完成任务。

2、如果没有安装sendmail组件,就要接用smtp服务器来发送了。这样相对较复杂,要引用一个PHP类。具体代码如下:

SMTP.PHP:
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;

/* Private Variables */
var $sock;

/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()

#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;

#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";

$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header = "MIME-Version:1.0\r\n";

if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}

$header .= "To: ".$to."\r\n";

if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}

$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";

list($msec, $sec) = explode(" ", microtime());

$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

$TO = explode(",", $this->strip_comment($to));

if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}

if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}

$sent = TRUE;

foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);

if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}

fclose($this->sock);

$this->log_write("Disconnected from remote host\n");
}

return $sent;
}

/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{

return $this->smtp_error("sending HELO command");
}

#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}

if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}

#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}

if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}

if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}

if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}

if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}

return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}

$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}

foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}

$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}

$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");

if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
$cmd = $arg;
else
$cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;
}

flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}

function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}

function smtp_debug($message)
{
if ($this->debug)
{
echo $message;
}
}
}
?>

DEMO:TEST.PHP
<?php
require "smtp.php";
$smtpserver = "smtp.xxx.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱
$smtpemailto = "[email protected]";//发送给谁
$smtpuser = "xxxx";//SMTP服务器的用户帐号
$smtppass = "xxxx";//SMTP服务器的用户密码
$mailsubject = "客户反馈意见!";//邮件主题
$mailbody = "<h1>这是我的一个测试~~~</h1>";//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = false;//是否显示发送的调试信息
$return = ($smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype));
echo $return;
?>

8、协议: SMTP, 服务器响应: '554 refused 'helo'/'ehlo' because hostname(workgroua19f93)

这个提示是服务器给你的回信,意思是说对方收件服务器拒绝你了你的邮件,所以被退回了。你可以联系一下对方邮件服务器的管理员查看一下日志看看究竟是什么原因导致你的邮件被拒收了,可能原因是某些过滤规则。

9、PHP 向邮箱发数据

类:smtp.php
<?php
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML")
{
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "")
{
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "")
{
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to)
{
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to))
{
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))
{
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else
{
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo))
{
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth)
{
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user)))
{
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass)))
{
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">"))
{
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">"))
{
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA"))
{
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body))
{
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom())
{
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT"))
{
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "")
{
return $this->smtp_sockopen_mx($address);
}
else
{
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("", "\1", $address);
if (, $MXHOSTS))
{
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host)
{
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok()))
{
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response))
{
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "")
{
if($cmd=="")
{
$cmd = $arg;
}
else
{
$cmd = $cmd." ".$arg;
}
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "")
{
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if () || !($fp = @fopen($this->log_file, "a")))
{
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address))
{
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug)
{
echo $message;
}
}
}
?>

<?php
/*
这是一个测试程序!!!
*/
require("smtp.php");
##########################################
$smtpserver = "smtp.126.com";//SMTP服务器
$smtpserverport = 25;//SMTP服务器端口
$smtpusermail = "服务器的用户邮箱
$smtpemailto = "发送给谁
$smtpuser = "";//SMTP服务器的用户帐号
$smtppass = "";//SMTP服务器的用户密码
$mailsubject = "中文";//邮件主题
$mailbody = "<h1>中文</h1>";//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
##########################################
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = TRUE;//是否显示发送的调试信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
?>

10、搭建red hat 5.0的postfix邮件服务器时,在smtp发送邮件测试的时候就HELO卡住了??!

是ehlo吧!对postfix的测试设置

[root@localhost ~]# telnet 127.0.0.1 25

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

220 mail.vbird.tsai ESMTP Postfix

ehlo vbird.tsai

250-mail.vbird.tsai

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

vrfy ethnicity

252 2.0.0 ethnicity

quit

221 2.0.0 Bye

Connection closed by foreign host.

与smtp服务器的helo域名相关的知识