标签 smtp 下的文章

cPanel - WHM - The SMTP restriction - 限制用户使用外部smtp发信

问题:cPanel用户无法通过php使用外部smtp服务器发信。

尝试:执行如 openssl s_client -connect smtp.gmail.com:465 的命令,显示cPanel/WHM本机的ssl证书,并不是gmail的。

解决:登录到WHM,禁用 The SMTP restriction 功能即可。

This feature prevents users from bypassing the mail server to send mail, a common practice used by spammers.
It will allow only the MTA, mailman, and root to connect to remote SMTP servers.

This control is also adjustable in Tweak Settings.

The SMTP restriction is enabled.

参考:https://docs.cpanel.net/whm/security-center/smtp-restrictions/

为远程桌面连接设置邮件提醒

需求:远程桌面连接Windows 2012时,会收到邮件提醒,提醒内容包含登录者的IP信息。

1.创建一个vbs脚本,能通过外部的smtp服务器发出邮件的

2.创建一个“定时任务”,条件是用户登录时运行,运行上边创建好的vbs脚本

3.如果通知内容还需带上远程桌面登录者的IP,可以在vbs脚本上加上提取IP的内容

例子:

set sh = CreateObject("Wscript.Shell") 
set Connections = CreateObject("Scripting.Dictionary") 

call Main() 

Function Main() 
    call GetConnections() 
    call ProcessConnections() 
End Function 

Function GetConnections() 
    i = 0 
    set shExec = sh.Exec("netstat -f") 

    Do While Not shExec.StdOut.AtEndOfStream 
        Line = shExec.StdOut.ReadLine() 
        If Instr(Line, "TCP") <> 0 Then 
            Set Connection = New NetworkConnection 
            Connection.ParseText(Line) 
            call Connections.Add(i, Connection) 
            i = i + 1 
        End If 
    Loop 
End Function 

Function ProcessConnections() 
    For Each ConnectionID in Connections.Keys 
        'wscript.echo ConnectionID & Connections(ConnectionID).RemoteIP
    Next 
End Function 

Class NetworkConnection 
    Public Protocol 
    Public LocalIP 
    Public LocalPort 
    Public RemoteIP 
    Public RemotePort 

    Public Sub ParseText(Line) 
        dim i 

        For i = 5 to 2 Step -1 
            Line = Replace(Line, String(i, " "), " ") 
        Next 

        Line = Replace(Line, ":", " ") 
        Line = Right(Line, Len(Line) - 1) 
        Line = Split(Line, " ") 

        Protocol = Line(0) 
        LocalIP = Line(1) 
        LocalPort = Line(2) 
        RemoteIP = Line(3) 
        RemotePort = Line(4) 

    End Sub 

    Private Sub Class_Initialize 
        'MsgBox "Initialized NetworkConnection object" 
    End Sub 

End Class

NameSpace = "http://schemas.microsoft.com/cdo/configuration/" 
Set Email = CreateObject("CDO.Message") 
Email.From = "18900000000@189.cn" 
Email.To = "18900000000@189.cn" 
Email.Subject = "有人登陆服务器 - " & ConnectionID & Connections(ConnectionID).RemoteIP
Email.Textbody = "注意检查登陆者是否合法!" 
With Email.Configuration.Fields 
.Item(NameSpace&"sendusing") = 2 
.Item(NameSpace&"smtpserver") = "smtp.189.cn" 
.Item(NameSpace&"smtpserverport") = 25 
.Item(NameSpace&"smtpauthenticate") = 1 
.Item(NameSpace&"sendusername") = "18900000000" 
.Item(NameSpace&"sendpassword") = "youxiangmima" 
.Update 
End With 
Email.Send

参考:

用telnet测试远程smtp发信

问题:如想简单测试远程smtp账户信息是否正确,能否发信,用telnet可以吗?

尝试:

telnet 148.163.x.x 25
Trying 148.163.x.x...
Connected to 148.163.x.x.
Escape character is '^]'.
220 mail.xxx.com ESMTP Postfix
EHLO mail.xxx.com # 打招呼
250-mail.xxx.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH LOGIN # 请求验证
334 VXNlcm5hbWU6
bGl1b2ZvQHVwdXN0cm333333bQ== # base64加密后的用户名
334 UGFzc3dvcmQ6 
MXEydz44444Tg3 # base64加密后的密码
535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6 #验证错误
AUTH LOGIN
334 VXNlcm5hbWU6
bGl3333v
334 UGFzc3dvcmQ6
MXEydz44443
235 2.7.0 Authentication successful #验证成功
MAIL FROM:liuo@xxx.com # 发件人
250 2.1.0 Ok
RCPT TO:liu@anqun.net #收件人
250 2.1.5 Ok
DATA #开始写信
354 End data with <CR><LF>.<CR><LF>
Subject:Sending email using Telnet #标题

This is just a simple test.
. # 写信结束
250 2.0.0 Ok: queued as 4831E40AFD2B
QUIT #退出
221 2.0.0 Bye
Connection closed by foreign host.

telnet-smtp-auth-test.png

如想在Linux的Shell里一句话发信测试,可:echo "Subject: hello" | sendmail liu@anqun.net

参考:https://www.kongtechnology.com/2008/01/27/smtp-authentication-and-send-emails-using-telnet/

Magento2的SMTP Pro测试发送gmail邮件失败 - cPanel

现象:WHM/cPanel环境里安装了Magento2,想通过SMTP Pro用gmail的邮件服务发邮件。邮件发送测试时提示出错:SMTP Pro Self Test Results: Exception message was: Unable to connect via TLS

过程:

1.确认php环境是支持openssl的,发信测试也是一样的失败结果
magento-smtp-gmail-ssl-1.png

2.搜索得,需要在WHM的Tweak Settings中,将“Restrick outgoing SMTP to root, exim, and mailman(FKA SMTP Tweak)”的功能关闭(设置为Off)
magento-smtp-gmail-ssl-3.png

3.重新测试发信,正常了

参考:https://magento.stackexchange.com/questions/22227/transactional-emails-not-going-out/22233#22233?newreg=72b194287746436db1f4744ce11838b4