我在VB.NET中构建了一个非常简单的SMTP服务器,只接收邮件...我需要支持票证系统。
我测试了我的服务器,发送了来自雅虎,Aol和巴西提供商BOL(www.bol.com.br)的电子邮件,并且它正在运行......
我服务器上的AOL传入消息示例:
Starting listening on port 25
Client connected: 64.12.143.76:44965
>>> 220 raptor.agoge.com.br Simple Mail Transfer Service Ready
<<< EHLO omr-m02.mx.aol.com
>>> 502 Command not implemented
<<< HELO omr-m02.mx.aol.com
>>> 250 raptor.agoge.com.br
<<< MAIL FROM:<fernando.nandissimo@aim.com>
>>> 250 OK
<<< RCPT TO:<f@frg.io>
>>> 250 OK
<<< DATA
>>> 354 Start mail input; end with <CRLF>.<CRLF>
<<< Received: from mtaomg-mbd02.mx.aol.com (mtaomg-mbd02.mx.aol.com [172.26.252.16])
by omr-m02.mx.aol.com (Outbound Mail Relay) with ESMTP id 1ED7C700000AB
for <f@frg.io>; Tue, 22 Jul 2014 22:19:39 -0400 (EDT)
Received: from core-mpa004a.r1000.mail.aol.com (core-mpa004.r1000.mail.aol.com [172.29.184.13])
by mtaomg-mbd02.mx.aol.com (OMAG/Core Interface) with ESMTP id E3BD638000082
for <f@frg.io>; Tue, 22 Jul 2014 22:19:38 -0400 (EDT)
To: f@frg.io
Subject: hello, how are you
X-MB-Message-Source: WebUI
X-MB-Message-Type: User
MIME-Version: 1.0
From: Fernando Guimaraes <fernando.nandissimo@aim.com>
Content-Type: multipart/alternative;
boundary="--------MB_8D17433B04EB4D2_2B44_5B1EE_webmail-d298.sysops.aol.com"
X-Mailer: AOL Webmail STANDARD
Received: from 177.205.201.180 by webmail-d298.sysops.aol.com (205.188.93.240) with HTTP (WebMailUI); Tue, 22 Jul 2014 22:19:38 -0400
Message-Id: <8D17433B04C5371-2B44-1B49B@webmail-d298.sysops.aol.com>
X-Originating-IP: [177.205.201.180]
Date: Tue, 22 Jul 2014 22:19:38 -0400 (EDT)
x-aol-global-disposition: G
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mx.aim.com;
s=20140625; t=1406081979;
bh=N2MgG06dHoS+gfxHvx3fcZZfnE5ajRhrD7hZ6uGTXOo=;
h=From:To:Subject:Message-Id:Date:MIME-Version:Content-Type;
b=AjcPEJldvpndBhlEONuynHpGLH75o7YFoVVf1yJ4VH7t3XZuuLCoTQHHvsxP99i2M
TOWiUfRLUqUBAwniVQnm3ccymbW56LlABsjMCfPXZdu0jEOnAvSzYcZDWXL7Pekfhf
GBM0ZMWkM62zFcWPwATnoWT24dyrclQ1F1R7i19Y=
x-aol-sid: 3039ac1afc1053cf1bba3fb7
This is a multi-part message in MIME format.
----------MB_8D17433B04EB4D2_2B44_5B1EE_webmail-d298.sysops.aol.com
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
hey!
i'm poking you... :)
----------MB_8D17433B04EB4D2_2B44_5B1EE_webmail-d298.sysops.aol.com
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
<font color=3D'black' size=3D'2' face=3D'arial'>hey!
<div><br>
</div>
<div>i'm poking you... :)</div>
</font>
----------MB_8D17433B04EB4D2_2B44_5B1EE_webmail-d298.sysops.aol.com--
.
>>> 250 OK
<<< QUIT
>>> 221 raptor.agoge.com.br closing transmission channel
雅虎邮件的另一个样本:
Starting listening on port 25
Client connected: 98.136.216.146:33362
>>> 220 raptor.agoge.com.br Simple Mail Transfer Service Ready
<<< EHLO nm27-vm3.bullet.mail.gq1.yahoo.com
>>> 502 Command not implemented
String unknow command: |EHLO nm27-vm3.bullet.mail.gq1.yahoo.com
|Binary unknow command: |45-48-4C-4F-20-6E-6D-32-37-2D-76-6D-33-2E-62-75-6C-6C-65-74-2E-6D-61-69-6C-2E-67-71-31-2E-79-61-68-6F-6F-2E-63-6F-6D-0D-0A|
<<< HELO nm27-vm3.bullet.mail.gq1.yahoo.com
>>> 250 raptor.agoge.com.br
<<< MAIL FROM:<dexterbhz@yahoo.com.br>
>>> 250 OK
<<< RCPT TO:<test@frg.io>
>>> 250 OK
<<< DATA
>>> 354 Start mail input; end with <CRLF>.<CRLF>
<<< Received: from [216.39.60.182] by nm27.bullet.mail.gq1.yahoo.com with NNFMP; 23 Jul 2014 02:26:07 -0000
Received: from [98.137.12.192] by tm18.bullet.mail.gq1.yahoo.com with NNFMP; 23 Jul 2014 02:26:07 -0000
Received: from [127.0.0.1] by omp1000.mail.gq1.yahoo.com with NNFMP; 23 Jul 2014 02:26:07 -0000
X-Yahoo-Newman-Property: ymail-3
X-Yahoo-Newman-Id: 66768.46477.bm@omp1000.mail.gq1.yahoo.com
Received: (qmail 17157 invoked by uid 60001); 23 Jul 2014 02:26:06 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.br; s=s1024; t=1406082366; bh=6Nqij6v2JUJTeT0/BhAdXEB0UBBXs1FyYLy0j8zf6s0=; h=Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=ikMGg1zk9izkqR5igwOCPcO/QSg6XVJhgIbq5CMiKGOmQp0XpSQXKRg87I3qBUCsx+d9U1bfMSGTdv9R/XrwFkAeNZd++ElFzsiCLhIvQe9QzQyRLpGc7E0/seMaeZYlMb16d2AE75zJWYnY1ziR/1LLXsBeDiO3aBgI5PlNnRA=
X-YMail-OSG: fg5x5oAVM1mGE8m_zI2LdNcCUFnHaR441eGqkmpjeD1r95V
TiUs7_8L297g1K1P665uhi2_5kSfpsywr53tuodffiVbEVmAQdlYfnqgc0IY
.s..ja4QTWjAv.QnKhFVgbRgsz8CaLLpw2kEoRAGnkkOW9MnP0aLg9bY1Ey.
plPmoUJwnSoSUgx4pO2ZdCrdu0uvR7G6MCtzNcF6g2OBZmGQ6dtY_qqdUNcv
9twltxpv6.iwQDBHwuheGxQRNdYNOP1WDwBqV9LrbFJ4sRAwIpDOt18wReUH
gcdX5xhUb.VcqM273IRwYodK9JQumd_r3NGzIxlZ47KPzrLRbCHY9Fc2MrjS
ujPF8pn5t814.gQvh2hVWnhXs0bAsSZFxH0UNGo3azIC8lukPcrVaFOn0o51
sMrF9gR.KYJAScvycM2C6ShLgzvxylkFpVqBdYNVVYQmOjzt8fK78YiVGWeJ
t0OEy0Rz21B74.hfydeYuExZKicFJlf1yjgS6tnv7o9DGLTuD2r5MAZ3YhLO
vYK4F5PKOZLUM8q.YmZTrOg1kPi9kyEb.kQWl7I.MtkiWqjIuqlbEfA--
Received: from [177.205.201.180] by web164003.mail.gq1.yahoo.com via HTTP; Tue, 22 Jul 2014 19:26:06 PDT
X-Rocket-MIMEInfo: 002.001,SXQgd2lsbCB3b3JrPwEwAQEBAQ--
X-Mailer: YahooMailWebService/0.8.195.680
Message-ID: <1406082366.16792.YahooMailNeo@web164003.mail.gq1.yahoo.com>
Date: Tue, 22 Jul 2014 19:26:06 -0700
From: Fernando Guimaraes <dexterbhz@yahoo.com.br>
Reply-To: Fernando Guimaraes <dexterbhz@yahoo.com.br>
Subject: It will work?
To: "test@frg.io" <test@frg.io>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="133570123-1133622410-1406082366=:16792"
--133570123-1133622410-1406082366=:16792
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
It will work?
--133570123-1133622410-1406082366=:16792
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html><body><div style=3D"color:#000; background-color:#fff; font-family:He=
lveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;fo=
nt-size:12pt"><div>It will work?</div></div></body></html>
--133570123-1133622410-1406082366=:16792--
>>> 250 OK
<<< .
>>> 250 OK
<<< QUIT
>>> 221 raptor.agoge.com.br closing transmission channel
但是GMAIL根本不跟我说话!
当GMAIL与我联系时,他们只发送了:
Starting listening on port 25
Client connected: 209.85.215.46:32845
>>> 220 raptor.agoge.com.br Simple Mail Transfer Service Ready
<<< EHLO mail-la0-f46.google.com
QUIT
>>> 502 Command not implemented
不要继续!?!...为什么?在EHLO失败后,GMAIL不应该发送HELO命令吗?
这是我接收该邮件的VB.NET代码:
Imports System.IO
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
'Add a TEXTBOX1 to form
'Add a TEXTBOX1 to form
'Add a TEXTBOX1 to form
'Add a TEXTBOX1 to form
Private Server As Sockets.TcpListener
Private Port As Integer = 25
Private Thread As Thread
Delegate Sub LogCallback(S As String)
Sub Log(S As String)
If Me.TextBox1.InvokeRequired Then
Dim d As LogCallback = AddressOf Log
Me.Invoke(d, S)
Else
Me.TextBox1.AppendText(S.Replace("\n", vbCrLf))
End If
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
Me.Text = String.Format("Listening port {0} v{1}", Port, AppVersion)
Thread = New Thread(New ThreadStart(AddressOf Listening))
Thread.Start()
End Sub
Async Function Listening() As Task
Server = New Sockets.TcpListener(Net.IPAddress.Any, Port)
Server.Start()
Log("Starting listening on port 25\n\n")
Do
Dim HandleThread As New Thread(New ParameterizedThreadStart(AddressOf HandleConnection))
HandleThread.Start(Await Server.AcceptTcpClientAsync)
Loop
End Function
Async Function HandleConnection(TcpClient As TcpClient) As Task
Dim Stream As NetworkStream = TcpClient.GetStream
Log(String.Format("\nClient connected: {0}\n", TcpClient.Client.RemoteEndPoint.ToString))
Await R(Stream, String.Concat("220 raptor.agoge.com.br Simple Mail Transfer Service Ready", vbCrLf))
While True
Do
Dim BuffSize As Integer = 4096
Dim Buffer As Byte() = New Byte(BuffSize - 1) {}
Dim BytesRead As Integer
BytesRead = Await Stream.ReadAsync(Buffer, 0, Buffer.Length)
If BytesRead = 0 Then Exit Function
Dim Msg As String = Encoding.ASCII.GetString(Buffer.Take(BytesRead).ToArray)
Log(String.Concat("<<< ", Msg))
If Msg.StartsWith("HELO") Then
Await R(Stream, "250 raptor.agoge.com.br")
ElseIf Msg.StartsWith("MAIL") Or Msg.StartsWith("RCPT") Or Msg.StartsWith("Date") Or Msg.StartsWith("From") Then
Await R(Stream, "250 OK")
ElseIf Msg.StartsWith("DATA") Then
Await R(Stream, "354 Start mail input; end with <CRLF>.<CRLF>")
ElseIf Msg.StartsWith("From") Or Msg.StartsWith("Received") Then
Await R(Stream, "250 OK")
ElseIf Msg = String.Concat(".", vbCrLf) Then
Await R(Stream, "250 OK")
ElseIf Msg.StartsWith("QUIT") Then
Await R(Stream, "221 raptor.agoge.com.br closing transmission channel")
Stream.Close()
TcpClient.Close()
Exit Function
Else
Await R(Stream, "502 Command not implemented")
End If
Loop While Stream.DataAvailable
End While
End Function
Private AppVersion As Integer = 32
Async Function R(Stream As NetworkStream, Message As String) As Task
Dim ResponseBuffer As Byte() = Encoding.ASCII.GetBytes(String.Concat(Message, vbCrLf))
Await Stream.WriteAsync(ResponseBuffer, 0, ResponseBuffer.Length)
Log(String.Concat(">>> ", Message, vbCrLf, vbCrLf))
End Function
End Class
答案 0 :(得分:1)
我解决了这个问题...
220响应的单个额外CRLF是问题......
错误的代码
Await R(Stream, String.Concat("220 raptor.agoge.com.br Simple Mail Transfer Service Ready", vbCrLf))
更正代码
Await R(Stream, "220 raptor.agoge.com.br Simple Mail Transfer Service Ready")