public static GetCurrentMIMEDateTime ( ) : string | ||
Résultat | string |
public bool Send(string sFrom, List <string> lstRecipients, string sSubject, string sBody) { if (!m_oSocket.Connect(_ipaddress, _port)) { return(false); } // Receive welcome message. string sData = m_oSocket.Receive(); m_oSocket.Send("HELO 127.0.0.1\r\n"); sData = m_oSocket.Receive(); // User m_oSocket.Send("MAIL FROM:<" + sFrom + ">\r\n"); sData = m_oSocket.Receive(); string sCommaSeparatedRecipients = ""; foreach (string sRecipient in lstRecipients) { m_oSocket.Send("RCPT TO:<" + sRecipient + ">\r\n"); sData = m_oSocket.Receive(); if (!sData.StartsWith("250")) { return(false); } if (sCommaSeparatedRecipients.Length > 0) { sCommaSeparatedRecipients += ", "; } sCommaSeparatedRecipients += sRecipient; } // Select inbox m_oSocket.Send("DATA\r\n"); sData = m_oSocket.Receive(); if (sCommaSeparatedRecipients.Length > 5000) { sCommaSeparatedRecipients = sCommaSeparatedRecipients.Substring(0, 5000); } m_oSocket.Send("From: " + sFrom + "\r\n"); m_oSocket.Send("To: " + sCommaSeparatedRecipients + "\r\n"); m_oSocket.Send("Subject: " + sSubject + "\r\n"); m_oSocket.Send("Date: " + Utilities.GetCurrentMIMEDateTime() + "\r\n"); m_oSocket.Send("\r\n"); // Send body m_oSocket.Send(sBody); m_oSocket.Send("\r\n"); m_oSocket.Send(".\r\n"); // Wait for OK. sData = m_oSocket.Receive(); if (sData.Substring(0, 3) != "250") { return(false); } // Quit again m_oSocket.Send("QUIT\r\n"); sData = m_oSocket.Receive(); m_oSocket.Disconnect(); return(true); }