A VB.NET code, generate mail, send mail, support SMTP to verify the username password.

xiaoxiao2021-03-06  14

You can generate a message, you can send a message, you can write into a COM component slightly, call it in the ASP. I will finish it into a complete.

'------------------------------------- 'Generate basic mail formats (including attachments), send mail to the SMTP server,' can only send the sender SMTP server (required to verify), direct delivery function is being written. '' Declaration: There is a piece of C # code for the online heroes of the Internet. Because I can't find the original text, I can't write the original author's name '' code write: head is too halo 'QQ: 25382888'msn : qq2538288@hotmail.com'blog: http://spacs.msn.com/members/headfaint http://blog.9cbs.net/super852'----------------- ------------------------------- Imports Systemimports System.Textimports System.Ioimports System.Netimports System.Net. Socketsimports System.Net. Socketsimports System .CollectionsNameSpace Ewebmail Public Class Mail 'Mail class, generate basic mail format.

Visit the author BLOG: http://spaces.msn.com/members/headfaint Public Charset As String = "GB2312" Public From As String Public FromName As String Public ReplyTo As String Public Subject As String = "" Public isHtml As Boolean = False . Public Body As String = "" Public TextBody As String = "This is a HTML mail" Public RecipientMaxNum As Integer = 15 'of the maximum number of recipients visit BLOG: http://spaces.msn.com/members/headfaint Public recipient As New ArrayList Public RecipientCC As New ArrayList Public RecipientBCC As New ArrayList Protected mPriority As String = "Normal" Protected boundary As String = "===== 000_eWebMail0099887766554433 _ =====" Protected boundary1 As String = "===== 001_eWebMail0099887766554433 _ ===== "Protected Attachments As New ArrayList Protected AttachmentsSB As New StringBuilder Protected RecipientName As String =" "Private Shared fileHT As Hashtable Shared Su b New () 'Add some common file format Access the author blog: http://spaces.msn.com/members/headfaint fileht = new hashtable fileht.add (". 323", "text / h323") Fileht.add (".3G2", "VIDEO / 3GPP2") Fileht.Add (". 3GP", "Video / 3GPP") Fileht.Add (". Act", "Text / XML") Fileht.Add (". ActProj" "Text / Plain") Fileht.Add (". Ai", "Application / PostScript") Fileht.Add (". AIF", "Audio / AIFF"

FILEHT.Add (". AIFC", "Audio / AIFF") Fileht.Add (". AIFF", "Audio / AIFF") Fileht.Add (". ASA", "Text / asa") Fileht.add ( ".ASF", "VIDEO / X-MS-ASF") Fileht.Add (". ASM", "Text / Plain) Fileht.Add (". ASP "," Text / Asp ") Fileht.Add (" .asx "," VIDEO / X-MS-ASF ") Fileht.add (". Au "," Audio / Basic ") Fileht.Add (". Avi "," VIDEO / AVI ") Fileht.Add (". BMP "," image / bmp ") Fileht.add (". C "," text / plain ") Fileht.add (". cat "," application / vnd.ms-pki.seccat ") fileht.add (" .cc "," text / place ") Fileht.Add (". CDF "," Application / X-Netcdf ") Fileht.Add (". CER "," Application / X-X509-CA-CERT ") Fileht. AddHt.Add (". CPP", "text / plain") fileht.add (". CPP", "text / plain") fileht.add (". CRL "" Application / Pkix-CRL ") Fileht.Add (". CRT "," Application / X-X509-CA-CERT ") Fileht.Add (". Cs "," Text / Plain ") Fileht.Add (". CSS", "text / css") Fileht.add (". CXX", "text / plain") Fileht.add (". dbs", "text / plain") fileht.add (" .def "," text / plain ") Fileht.add (". Der "," Application / X-X509-CA-CAT ") Fileht.Add (". Dib "," Image / BMP ") Fileht.Add ( ".dll", "

Application / X-msdownLoad ") Fileht.add (". DOT ",". Dot "," Application / Msword ") Fileht.Add (". DPS "," Interface / VND) .divx-skin ") Fileht.add (". DSP "," text / place ") Fileht.add (". DSW "," text / place ") Fileht.add (". DXU "," VIDEO / VND. DivX-PlayList ") Fileht.add (". EDN ",". EML ",". EML "," MESSAGE / RFC822 ") Fileht.Add (". EPS "," Application / postscript ") Fileht.add (". ETD "," Application / X-EBX ") Fileht.Add (". ETP "," Text / Plain ") Fileht.Add (". EXE "," Application / X- ") Fileht.add (". ext "," text / plain ") Fileht.add (". fdf "," Application / VND.FDF ") Fileht.Add (" .fif "," Application / Fractals ") Fileht.add (". fky", "text / plain") fileht.add (". gif", "image / gif") fileht.add (". h", "text / plain") fileht.add (" .hpp "," text / plain ") Fileht.add (". HQX "," Application / Mac-Binhex40 ") Fileht.add (". hta ",". htc ",". htc ",". htm ") Fileht.add (". htm ") "Text / HTML") Fileht.add (". html", "text / html") Fileht.add (". htt", "text / WebViewHtml") Fileht.add (". htx", "text / html "

FILEHT.Add (". Hxx", "text / plain) fileht.add (". I "," text / plain ") Fileht.add (". ICO "," Image / X-icon ") Fileht. Add (". IDL", "text / plain") Fileht.add (". III", "Application / X-iPhone") Fileht.add (". Inc", "text / plain") Fileht.Add (" .inl "," text / place ") Fileht.Add (". ISP ",". ISP ",". ISP "," Application / X-Internet-Signup ") FILEHT. Add (". Java", "Java / *") Fileht.Add (". JFIF", "Image / JPEG") FILEHT.ADD (". JPE", "Image / JPEG") Fileht.Add (". JPEG "," image / jpeg ") fileht.add (". jpg "," image / jpeg ") Fileht.add (". JS "," Application / X-JavaScript ") Fileht.Add (". kci "," FILEHT.Add (". LGN", "Text / Plain") Fileht.Add (". LGN", "Text / Plain") FILEHT.ADD (". ls", "Application / X -javascript ") Fileht.add (". LST "," text / plain ") fileht.add (". m1v "," VID EO / MPEG ") Fileht.Add (". M3U "," Audio / X-MPEGURL ") Fileht.Add (". Mak "," Text / Plain ") Fileht.Add (" .man "," Application / X -Troff-man ") Fileht.add (". MAP "," text / plain ") Fileht.add (". MDB "," Application / Msaccess ") Fileht.add (". MFP "," Application / X- ShockWave-Flash "

FILEHT.Add (". MHT", "Message / RFC822") Fileht.add (". MHTML", "Message / RFC822") Fileht.Add (". MID", "Audio / MID") Fileht.Add ( ".midi", "Audio / MID") Fileht.add (". MK", ". Mocha", "Application / X-JavaScript") FILEHT.Add (". Movie "" Video / X-SGI-MOVIE ") Fileht.Add (". MP2V ",". MP2V "," Video / MPEG ") Fileht.Add (". MP3 " , "Audio / MPEG") Fileht.Add (". MPA", "VIDEO / MPEG") Fileht.Add (". MPE", "Video / MPEG") Fileht.Add (". MPEG", "Video / MPEG ") Fileht.add (". MPG "," VIDEO / MPEG ") Fileht.add (". MPV2 "," Video / MPEG ") Fileht.Add (". NMW "," Application / NMWB ") Fileht.Add (".nws", "Message / RFC822") Fileht.Add (". ODH", "Text / Plain") Fileht.Add (". ODL", "Text / Plain") Fileht.Add (". p10" , "Application / PKCS10") Fileht.Add (". P12", "Application / X-PKCS12") Fileht.add (". P7b", "Application / X-PKCS7-Certificate") Fileht.add (". P7C", "Application / PKCS7-MIME") Fileht.Add (". p7m", "Application / PKCS7- ") Fileht.add (". p7r "," application / x-pkcs7-certreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqreqresp ") Fileht.add (". PDF ") Fileht.Add (". PDF "

, "Application / PDF") Fileht.Add (". PDX", "Application / VND.adobe.pdx") Fileht.add (". PFX", "Application / X-PKCS12") Fileht.Add (". PKO "," Application / Vnd.ms-Pki.pko ") Fileht.Add (". pl ",". plg ",". plg "," text / html ") Fileht.add ( ".png", "image / png") fileht.add (". prc", "text / plain) Fileht.add (" .prf "," Application / Pics-Rules ") Fileht.Add (". ps "" Application / PostScript ") Fileht.add (". py ",". pys "," text / plain ") Fileht.add (". pyw "," text) ") Fileht.Add (". ra "," audio / vnd.rn-realaudio) Fileht.add (". Ram", "Audio / X-PN-ReaRaudio") Fileht.Add (". Rat", "Application / Rat-file") Fileht.Add (". RC2", ". RC2", "Text / Plain") Fileht.Add (". rct", "Text / PLAIN ") Fileht.Add (". RGS "," text / plain ") Fileht.add (". rjs "," Application / VN D.Rn-realsystem-rjs ") Fileht.add (". RJT "," Application / VND.RN-RealSystem-RJT ") Fileht.Add (". RM "," Application / VND.RN-RealMedia) Fileht Fileht.Add (". RMJ", "Application / Vnd.r", "Application / Vnd.r", "Application / VND.RN-RealSystem -rmj

FILEHT.Add (". RMM", "Audio / X-PN-ReaRaudio") Fileht.Add (". RMP", "Application / VND.RN-RN_MUSIC_PACKAGE") Fileht.Add (". RMS", "Application /VND.RN-REALMEDIA-SECURE ") Fileht.Add (". RMVB "," Application / Vnd.rn-RealMedia-VBR ") Fileht.Add (". RMX "," Application / VND.RN-Realsystem-RMX ") Fileht.add (". RNX "," Application / Vnd.rn-realplayer ") Fileht.Add (". Rp ",". REALPIX ") fileht.add (". Rpm "," Audio / X-pn-realudio-plugin ") Fileht.Add (". RSML "," Application / VND.RN-RSML ") Fileht.Add (". RT "," Text / VND.RN-RealText ") Fileht .Add (". RTF", "Application / Msword") Fileht.add (". Rul", "text / place") Fileht.add (". Rv", "video / vnd.rn-realvideo") FILEHT. AddHt.Add (". SCT", "text / scriptlet") fileht.add (". Sit", "application / x-stuffit") Fileht.Add ("Application / X-stuffit") FILEHT.ADD (" .sln "," Application / OcTet-Stream ") Fileht.Add (". SMI ", "Application / SMIL") Fileht.Add (". SMIL", ". SND", "Audio / Basic") FILEHT.ADD (". Sol", "Text / Plain" FILEHT.Add (". Sor", "Text / Plain") Fileht.add (". SPC", "Application / X-PKCS7-Certificate") Fileht.Add (". SPL", "Application / Futuresplash") Fileht.add (". SQL"

"Text / Plain") Fileht.Add (". SRF", "text / plain") Fileht.add (". SST", "Application / VND.ms-Pki.certstore) Fileht.Add (". STL "," Application / Vnd.ms-Pki.stl ") Fileht.Add (". STM "," Text / HTML ") Fileht.Add (". SWF "," Application / X-ShockWave-Flash "FILEHT. Add (". Tab", "Text / Plain") Fileht.Add (". TDL", "Text / XML") Fileht.Add (". TIF", "Image / Tiff") Fileht.Add (". TIFF "," image / TIFF ") Fileht.add (". TLH ",". Tli "," Text / Plain ") Fileht.Add (". Torrent "," Application / X-Bittorrent ") Fileht.add (". TRG "," text / plain ") Fileht.add (". TXT "," text / plain) Fileht.add (". UDF", "text / plain") Fileht.add (". UDT", "Text / Plain") Fileht.add (". ULS", "Text / IULS") Fileht.Add (". User", "Text / Plain") Fileht.Add (" .usr "," text / plain ") Fileht.add (". VB "," text / plain) Fileht.add (". VCF", "T EXT / X-VCARD ") Fileht.add (". Vcproj "," text / plain) Fileht.add (". Viw", "text / plain) Fileht.add (". vspscc "," text / plain ") Fileht.add (". Vsscc "," text / place ") fileht.add (". Vsscc "," text / place ") Fileht.add (" WAV "," Audio / X-WAV "

Fileht.add (". Wax", "Audio / X-MS-Wax") Fileht.add (". Wiz", "Application / MSWORD") Fileht.Add (". WM", "VIDEO / X-MS -WM ") Fileht.add (". WMA "," Audio / X-MS-WMA ") Fileht.Add (". WMD "," Application / X-MS-WMD ") Fileht.Add (". WMV " "Video / X-MS-WMV") Fileht.Add (". WMX", "VIDEO / X-MS-WMX") Fileht.Add (". WMZ", "Application / X-MS-WMZ") Fileht .Add (". WPL", "Application / VND.MS-WPL") Fileht.Add (". WSC", "Text / Scriptlet") Fileht.Add (". Wvx", "VIDEO / X-MS-WVX ") Fileht.add (". Xbm "," image / x-xbitmap ") Fileht.add (". Xdp "," application / vnd.adobe.xdp xml ") Fileht.add (". Xfd "," Application / vnd.adobe.xfd XML ") Fileht.add (". xfdf "," Application / VND.ADobe.xfdf ") Fileht.add (". xls "," Application / VND.MS-Excel "Fileht .Add (". Xml", "text / xml") Fileht.add (". Xsl", "text / xml") Fileht.add (". Ymg", "Application / YMSGR") Fileht.a DD (". YPS", "Application / Ymsgr") Fileht.Add (". Z", "Application / X-Compress") End Sub Public Shared Function Getmime (Byval Strfilename As String) AS String 'Names according to the file extension Document format Visit the author blog: http://spaces.msn.com/members/headfaint if fileht (strfilename) <> Nothing the return fileht (strfilename) else returna "* / *"

End Function Public Property RcpName () As String 'name of the recipient of the visit BLOG: http://spaces.msn.com/members/headfaint Get If RecipientName <> "" Then Return RecipientName If Recipient.Count> 0 Then Return Recipient (0) RETURN "" "" End Get Set (Byval Value As String) RecipientName = Value End End Property Public Function AddRecipient (byval Str As String) AS Boolean 'Add a recipient address Access Author Blog: http: // spaces. Msn.com/members/headfaint return addrs (str, recipient) End function public function addRecipient (Byval str () AS String) AS Boolean 'Add a set of recipient Address access author blog: http://spaces.msn.com / members / headfaint Return addRs (str, Recipient) End Function Public Function AddRecipientCC (ByVal str () As String) As Boolean 'Add a group of CC address access BLOG: http://spaces.msn.com/members/headfaint Return AddRS (STR, RecipientCC) End Function Public Function AddRecipientBCC (ByVal str () As String) As Boolean 'to add a set of BCC address access BLOG: http://spaces.msn.com/members/headfaint Return addRs (str, RecipientBCC) End Function Public Function AddRecipientCC (ByVal str As String) As Boolean 'add a carbon-copy of the visit BLOG: http://spaces.msn.com/members/headfaint Return addRs (str, RecipientCC) End Function Public Function AddRecipientBCC (ByVal str As String) as boolean '

Add a BCC address access of BLOG: http://spaces.msn.com/members/headfaint Return addRs (str, RecipientBCC) End Function Protected Function addRs (ByVal str As String, ByRef ra As ArrayList) As Boolean 'add a Email address to a list Access the author blog: http://spaces.msn.com/members/headfaint str = str.-itxof ("@") = -1 Ten Return True End If If ra.Count

Visit the author BLOG: http://spaces.msn.com/members/headfaint If AttachmentStream.Length> 0 Then Attachments.Add (AttachmentName) Dim sl As Long = AttachmentStream.Length Dim barray (sl) As Byte Dim dotidx As Integer = AttachmentName.LastIndexOf ( ".") Dim strType As String If dotidx <> -1 Then strType = getMime (AttachmentName.Substring (dotidx)) Else strType = "* / *" AttachmentStream.Read (barray, 0, sl) AttachmentsSB. append ( "-" & boundary & vbNewLine) AttachmentsSB.Append ( "Content-Type:" & strType & "; name =" "" & AttachmentNameStr (AttachmentName.Substring (AttachmentName.LastIndexOf ( "/") 1)) & "" "" & vbNewLine) AttachmentsSB.Append ( "Content-Transfer-Encoding: base64" & vbNewLine) If strCID = "" Then strCID = getrndstr () End If AttachmentsSB.Append ( "Content-ID: <" & strCID & " "& VbNewLine) AttachmentsSB.Append (" Content-Disposition: attachment; filename = "" "& AttachmentNameStr (AttachmentName.Substring (AttachmentName.LastIndexOf (" / ") 1)) &" "" "& vbNewLine & vbNewLine) AttachmentsSB .Append (Base64.Strline (BASE64.STRLINE (BARRAY) & VBNEWLINE & VBNEWLINE) RETURN STRCID ELSE RETURN "ERROR NO DATA!"

Endiffstr () AS String 'When the ID is not set to the attachment, automatically generate an ID access author blog: http://spaces.msn.com/members/headfaint Dim Strtemp as string = "" DO While strTemp.Length <6 Randomize () strTemp = Chr (Int (26 * Rnd () 65)) Loop Return strTemp End Function Protected Function AttachmentNameStr (ByVal fn As String) As String 'creates a mail header of the visit BLOG: http : //spaces.msn.com/members/headfaint if encoding.default.getbytecount (fn)> fn.ley "=?" & charset.toupper () & "? b?" & base64.encode (fn) "? =" Else Return fn end if End function public protection priority () AS string 'Setting up the priority access author blog: http://spaces.msn.com/members/headfaint get return mPriority End Get Set (Byval Value as string) SELECT CASE VALUE Case "1", "high" mPriority = "high" case "3", "Normal" mPriority = "Normal" Case "5", "low" mPriority = "low" End SELECT End set End Property Public Overrides Function Tostring AS string 'Rewinds the TOSTRING method to output the overall mail format text.

'This is a very critical function to visit the author blog: http://spaces.msn.com/members/headfaint Dim sendbuffrstr as string dim strient as string if charset = "" "" "" "" "& fromname & "" <"& From &" & vbnewline else sendbuffrstr = "from:" =? "& Charset.toupper () &"? B? "& Base64.encode (fromname) &"? = "< "& From &"> & vbNewline End IF Replerto <> "" TENDBUFFERSTR = "reply-to:" & replyto & vbNewline if Recipient.count> 0 Then SendBufferstr = "TO:" for Each Stritem in Recipient SendBufferstr = strItem & "<" & strItem & ">," & vbNewLine Next SendBufferstr = SendBufferstr.Substring (0, SendBufferstr.Length - 3) & vbNewLine End If If RecipientCC.Count> 0 Then SendBufferstr = "CC:" For Each Stritem in Recipientcc Sendbufferstr = StrItem & "<" & strItem & ">," & vbNewLine Next SendBufferstr = SendBufferstr.Substring (0, SendBufferstr.Length - 3) & vbNewLine End If If RecipientBCC.Count> 0 Then SendBufferstr = "BCC:" For Each Stritem in RecipientBCC SendBufferstr =

strItem & "<" & strItem & ">," & vbNewLine Next SendBufferstr = SendBufferstr.Substring (0, SendBufferstr.Length - 3) & vbNewLine End If If Charset = "" Then SendBufferstr = "Subject:" & Subject & vbNewLine Else sendbufferstr = "Subject:" & "=?" & Charset.toupper () & "? B?"? = "& Vbnewline end if sendbufferstr =" x-priority: " & Priority & vbNewLine SendBufferstr = "X-MSMail-Priority:" & Priority & vbNewLine SendBufferstr = "Importance:" & Priority & vbNewLine SendBufferstr = "X-Mailer: eWebMail" & vbNewLine SendBufferstr = "MIME-Version: 1.0 "& vbNewline if attachments.count> 0 Then sendbufferstr =" Content-type: multipart / related; "& vbNewline &" Boundary = "" & boundary & ""; "& vbNewline &" Type = "Multipart / alternative "" "& vbNewline & Vbnewline Send Bufferstr = "This is a multipart message in MIME format." & VbNewLine & vbNewLine SendBufferstr = "-" & boundary & vbNewLine End If If isHtml Then SendBufferstr = "Content-Type: multipart / alternative;" & VBNewline & "Boundary ="

"" & Boundary1 & "" "" & vbNewLine & vbNewLine & vbNewLine SendBufferstr = "This is a multi-part message in MIME format." & VbNewLine & vbNewLine SendBufferstr = "-" & boundary1 & vbNewLine SendBufferstr = " Content-Type: Text / Plain; "& vbNewline if Charset =" "THEN DENDBUFFERST =" charset = "" ISO-8859-1 "" & VBNewline else sendbuffrstr = "charset =" "" & charset.tolower ) & "" "" & vbNewLine End If SendBufferstr = "Content-Transfer-Encoding: base64" & vbNewLine & vbNewLine SendBufferstr = Base64.strLine (Base64.Encode (TextBody)) & vbNewLine & vbNewLine & "-" & boundary1 & vbNewLine & "Content-Type: text / html;" & vbNewLine Else SendBufferstr = "Content-Type: text / plain;" & vbNewLine End If If charset = "" Then SendBufferstr = "charset =" "iso- 8859-1 "" "& vbnewli ne Else SendBufferstr = "charset =" "" & Charset.ToLower () & "" "" & vbNewLine End If SendBufferstr = "Content-Transfer-Encoding: base64" & vbNewLine & vbNewLine SendBufferstr = Base64.strLine (Base64 .Encode (body)) &

vbNewLine If isHtml Then SendBufferstr = vbNewLine & "-" & boundary1 & "-" & vbNewLine If Attachments.Count> 0 Then SendBufferstr = vbNewLine & AttachmentsSB.ToString () SendBufferstr = "-" & boundary & " - "& vbNewLine & vbNewLine End If Return SendBufferstr End Function End Class Class Base64 'encoded with BASE64 visit the author BLOG: http://spaces.msn.com/members/headfaint Public Shared Function encode (ByVal str As String) As String 'string of coded access BLOG: http://spaces.msn.com/members/headfaint Return Convert.ToBase64String (Encoding.Default.GetBytes (str)) End Function Public Shared Function Decode (ByVal str As string) As string 'string of decoding visit BLOG: http://spaces.msn.com/members/headfaint Return Encoding.Default.GetString (Convert.FromBase64String (str)) End Function Public Shared Function strLine (ByVal str As string) As string'Take a long string content by mail format Base64 encoding access author blog: http://spaces.msn.com/members/headfaint Dim B64SB As New StringBuilder Dim SL AS Integer = Str.Length - 76 DIM I as integer = 0 do while i

Send e-mail Visit using SMTP protocol BLOG: http://spaces.msn.com/members/headfaint Public SmtpServer As String = "" Public SmtpPort As Integer = 25 Public chkSmtp As Boolean = False Public smtpUserName As String = "" Public smtpPassWord As String = "" Protected Shared ErrCodeHT As New Hashtable Protected Shared RghCodeHT As New Hashtable Public Function send (ByVal strMailTo As String, ByVal MailFrom As String, ByVal strMail As String) As Boolean 'send e-mail visit BLOG: http: // spaces .msn.com / members / headfaint Dim SendBuffer As New ArrayList Dim SendBufferstr As String For Each SendBufferstr In strMailTo.Split ( ",") If Not SendBufferstr = "" Then SendBuffer.Add (SendBufferstr) Next If SendBuffer.Count = 0 Then Return False Return Send (Sendbuffer, Mailfrom, Strmail) End Function Public Function Send (Byval Strmailto As Arraylist, ByVal Mailfrom As String, BYV al strMail As String) As Boolean 'Send Message Access OF BLOG: http://spaces.msn.com/members/headfaint If strMailTo.Count = 0 Then Return False Dim tc As TcpClient Try tc = New TcpClient (SmtpServer, SmtpPort) Catch ex As Exception Return False End Try Dim ns As NetworkStream = tc.GetStream () Try 'access to the server to establish links of BLOG: http://spaces.msn.com/members/headfaint If RghCodeHT (RecvResponse (ns) .Substring (0, 3)) =

Nothing Then Return False Catch ex As Exception Return False End Try Dim SendBuffer As New ArrayList Dim SendBufferstr As String If chkSmtp Then 'verification of the username and password to access BLOG: http://spaces.msn.com/members/headfaint If Not SmtpAuth ( ns) Then Return False Else SendBufferstr = "HELO" & SmtpServer & vbNewLine If Not Dialog (SendBufferstr, ns) Then Return False End If SendBufferstr = "MAIL FROM: <" & MailFrom & ">" & vbNewLine 'send "MAIL FROM" Visit the author blog: http://spaces.msn.com/members/headfaint if not dialog (Sendbuffrstr, NS) Then Return False sendbuffer () for Each Sendbuffrstr in strMailto 'Send recipient Address Access Author Blog: http: //spacs.msn.com/members/headfaint if not sendbuffrstr = "" The sendbuffer.add ("RCPT TO: <" & sendbufferstr & "> & vbnewline) Next if not Dialog (Sendbuffer, NS) THEN RETUR n False SendBufferstr = "DATA" & vbNewLine 'send body and attachments accessed OF BLOG: http://spaces.msn.com/members/headfaint If Not Dialog (SendBufferstr, ns) Then Return False SendBufferstr = strMail & vbNewLine & ". "& vbnewline if not dialog (sendbufferstr, ns) Then Return False sendbufferstr =" quit "& vbnewline" completes the send,

Disconnect Access Author Blog: http://spaces.msn.com/members/headfaint if not sendcommand (Sendbufferstr, NS) Then Return False ns.close () tc.close () Return True End Function Public Function Send (BYVAL) eMail As Mail) As Boolean 'send e-mail visit BLOG: http://spaces.msn.com/members/headfaint Dim SendBuffer As New ArrayList Dim SendBufferstr As String For Each SendBufferstr In eMail.Recipient SendBuffer.Add (SendBufferstr) Next For each SendBufferstr In eMail.RecipientCC SendBuffer.Add (SendBufferstr) Next For each SendBufferstr In eMail.RecipientBCC SendBuffer.Add (SendBufferstr) Next Return Send (SendBuffer, eMail.From, eMail.ToString ()) End Function Protected Function SendCommand (ByVal Command AS String, Byref NS As NetworkStream) AS Boolean 'Sends a line command to the SMTP server to the author blog: http: // spac es.msn.com/members/headfaint Dim WriteBuffer () As Byte If Command.Trim () = "" Then Return True WriteBuffer = Encoding.Default.GetBytes (Command) Try ns.Write (WriteBuffer, 0, WriteBuffer.Length) Catch ex As Exception Return False End Try Return True End Function Protected Function Dialog (ByVal command As String, ByRef ns As NetworkStream) As Boolean 'sends a command line to the SMTP server, and the server waits for a response visit of BLOG: http: // spaces. Msn.com/members/headfaint if command.trim () = "" THEN RETURN TRUE IF SendCommand (Command, NS) Then Dim rr as string =

RecvResponse (ns) If RR = "false" Then Return False Try Dim RRCode As String = RR.Substring (0, 3) If RghCodeHT (RRCode) <> Nothing Then Return True Catch ex As Exception Return False End Try Return False Else Return False End If End Function Protected Function Dialog (ByVal command As ArrayList, ByRef ns As NetworkStream) As Boolean 'sends a command line to the SMTP server, wait for the server to respond to access off of BLOG: http://spaces.msn.com/members/headfaint Dim strCmd As String For Each strCmd In Command If Not Dialog (strCmd, ns) Then Return False Next Return True End Function Protected Function SmtpAuth (ByRef ns As NetworkStream) As Boolean 'sends the user name and password to the server to verify visit poster BLOG: http : //spaces.msn.com/members/headfaint Dim Sendbuffer AS New ArrayList Dim SE ndBufferstr As String SendBufferstr = "EHLO" & SmtpServer & vbNewLine 'transmits an EHLO command access OF BLOG: http://spaces.msn.com/members/headfaint If SendCommand (SendBufferstr, ns) Then Dim i As Integer = 0 Do If ns .Dataavailable kil rr as string = recvresponse (ns) if rr = "false" the return false dim RRCODE AS STRING = r.substring (0, 3) IF NOT RGHCODEHT (RRCODE) = Nothing the if rr.indexof ("Auth ") <>

-1 THEN EXIT DO ELSE RETURN FALSE END IF Else System.threading.Thread.Sleep (50) i = i 1 IF I> 60 THEN RETURSE END IF End If SendBuffer.Add ("Auth login "& vbnewline) 'Send a username password Access the author blog: http://spaces.msn.com/members/headfaint sendbuffer.add (base64.encode (smtpusername) & vbnewline) SendBuffer.add (Base64.encode (SMTPassword) & vbNewLine) Return Dialog (SendBuffer, ns) End Function Protected Function RecvResponse (ByRef ns As NetworkStream) As String 'receives a response from the SMTP server access author BLOG: http://spaces.msn.com/members/headfaint Dim streamSize As Integer DIM RETURNVALUE As String = "" DIM REA dBuffer (1023) As Byte Try StreamSize = ns.Read (ReadBuffer, 0, 1024) Catch ex As Exception Return "false" End Try If StreamSize = 0 Then Return "" Else ReturnValue = Encoding.Default.GetString (ReadBuffer) .Substring (0, streamsize) RETURN RETURNVALUE end if End Function Shared Sub New () Add a SMTP Refonation Information Comparison Hash Table Access the author blog: http://spacs.msn.com/members/headfaint errcodeht.add (" 500 "," Email Address Error ") Errcodeht.Add (" 501 "," Parameter Format Error ") errcodeht.add ("

502 "," The command is not implemented ") errcodeht.add (" 503 "," Server requires SMTP verification ") errcodeht.add (" 504 "," command parameters ") errcodeht.add (" 421 "," service is not Ready, turn off the transfer channel ") Errcodeht.add (" 450 ", the email operation required by the requirements is not completed, the mailbox is unavailable (for example, mailbox busy)") errcodeht.add ("550", ", the mail operation is not completed, Email (for example, mailbox is not found, or irresisible) ") Errcodeht.add (" 451 "," Abandon the requirements of the required operation; "Error during processing") errcodeht.add ("551", "User non-local, please Try ") Errcodeht.add (" 452 "," System Storage Insufficient, Not Executive Demand ") ErrcodeHt.Add (" 552 "," Excessive storage allocation, required operation ") errcodeht .Add ("553", "mailware name is not available, the required operation is not performed (such as a mailbox format error)") Errcodeht.Add ("432", "need a password conversion") errcodeht.add ("534", " The authentication mechanism is too simple ") Errcodeht.add (" 538 "," Current Request Certification Mechanism Requires Encryption ") Errcodeht.Add (" 454 "," Temporary Certification Failure ") Errcodeht.Add (" 530 "," Requirements " Rghcodeht.add ("220", "Service Ready") Rghcodeht.Add ("250", "Required Mail Operation") Rghcodeht.Add ("251", "User Non-local, will forward to ") Rghcodeht.Add (" 354 "," Start Mail Enter, "221", "Service Turn Transfer Channel") Rghcodeht.Add ("334", "Server Response Verification Base64 String") Rghcodeht.Add ("235", "Verification Success") End Sub End Classend Namespace

转载请注明原文地址:https://www.9cbs.com/read-45836.html

New Post(0)