Namespace jcpersonal.utility {using system; using system.net.sockets; using system.io; using system.text;
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
ReadString (TCP.GetStream ()); // Get connection information
// Start Server Certification // If the status code is 250, the operation is successful if (! Command (tcp.getStream (), "Ehlo LocalHost", "250") "" Land Drape Failure ");
IF (username! = ") {// requires authentication if (! Command (tcp.getStream ()," auth login "," 334 ")) throw new exception (" Authentication phase failed "); string nameb64 = Tobase64 (UserName); convert UserName to Base64 code if (! Command (tcp.getStream (), Nameb64, "334")) throw new exception ("Authentication phase failed"); string passb64 = tobase64 ( Password); // convert password to Base64 code if (! Command (TCP.GetStream (), Passb64, "235")) Throw new Exception ("Authentication Stage Failure");
// Prepare to send WRITESTRING (TCP.getStream (), "Mail from:" from); WritestRing (TCP.GetStream (), "RCPT TO: TO); WRITESTRING (TCP.GetStream ()," Data ") ;
// Send the mail head WritestRing (TCP.getStream (), "Date:" DateTime.Now); // Time WriteString (tcp.getStream (), "from:" fromname "<" from ">" ); // sender WritestRing (TCP.getStream (), "Subject:" Subject); // Topic WritestRing (TCP.GetStream (), "TO:" Toname "< to "> " ); // recipient // message format WriteString (tcp.getStream (), "Content-type: multipart / mix; boundary = /" unique-boundary-1 / "); WritestRing (TCP.getStream (), "Reply-to:" from); // Reply Address WritestRing (TCP.GetStream (), "X-Priority:" priority); // Priority WriteString (TCP.getStream (), "MIME-VERSION: 1.0 "); // MIME version
// Data ID, random // WriteString (TCP.getStream (), "Message-ID:" DateTime.now.tofiletime () "@ security.com"); WritestRing (TCP.GetStream (), "Content- Transfer-encoding: " Encoding); // Content Code WriteString (TCP.getStream ()," X-MAILER: JCPERSONAL.UTILITY.MAILSENDER "); // Mail sender WritestRing (TCP.getStream ()," ") ;
WriteString (TCP.getStream (), Tobase64 ("This Is A Multi-Part Message In Mime Format."); WritestRing (TCP.GetStream (), "")
/ / Start from this to the separation input WriteString (TCP.GetStream (), "--unique-Boundary-1");
/ / Define the second separator WRITESTRING (TCP.GETSTREAM (), "Content-Type: Multipart / Alternative; Boundary = /" Unique-Boundary-2 / "); WriteString (TCP.getStream (), "" "
IF (! iSHTML) {// Text Information WritestRing (TCP.GetStream (), "--unique-Boundary-2"); WritestRing (TCP.GetStream (), "Content-Type: Text / Plain; Charset =" LanguageEncoding; WritestRing (TCP.getStream (), "Content-Transfer-Encoding:" Encoding); WritestRing (TCP.getStream (), ""); WritestRing (TCP.getStream (), body); WritestString (TCP. GetStream (), ""); // After writing, you will write as empty information, segment WRITESTRING (TCP.GetStream (), "--unique-boundary-2 -"); // Separator end Symbols, behind the tails - WriteString (TCP.getStream (), "");} else {// HTML information WriteString (TCP.GetStream (), "--unique-Boundary-2"); WritestString (TCP. GetStream (), "Content-Type: Text / HTML; Charset =" LanguageEncoding); Writestring (TCP.GetStream (), "Content-Transfer-Encoding:" Encoding); WritestString (TCP.getStream (), "" ); Writestring (TCP.getStream (), HTMLBody; WritestRing (TCP.GetStream (), ""); Writestring (TCP.GetStream (), "--unique-Boundary-2 -"); // Deridiator The end symbol, there are more than the tail - WriteString (TCP.getStream (), "");
// Send an attachment // Take a loop for the file list for (int i = 0; i
// Close the connection tcp.close ();
///
// Translate the command line to Byte [] Byte [] bwrite = Encoding.GeteEncoding .getBytes (Str.ToChararray ());
// Since the size of each write is limited, then we will set the length of the data written to 75 bytes, once the command length exceeds 75, step by step. INT start = 0; intlength = bWrite.Length; int point = 75; int count = size; try {i (length> 75) {// Data page IF ((length / size) * Size < Length) Page = Length / Size 1; Else Page = Length / size; for (INT i = 0; i
///
///
///
///
///
// Use:
Mailsender ms = new mailsender (); ms.From = "jovenc@tom.com"; ms.to = "jovenc@citiz.net"; ms.subject = "subject"; ms.body = "body text"; ms .Username = "########"; // How can I tell you? Ms.password = "********"; // How can I tell you MS.Server = "SMTP. Tom.com ";
Ms.attachments.add (New Mailsender.attachmentInfo (@ "d: /test.txt"));