// 編碼 protected void bn_ecode_Click(object sender, EventArgs e) { CodeBase64 cb64 = new CodeBase64(); cb64.CodePage = int.Parse(tb_codepage.Text); cb64.DeBase64Code = tb_dcode.Text.Trim(); tb_ecode.Text = cb64.EnBase64Code; }
public bool SendMessage(SMTPMessage smtpMessage) { CodeBase64 codeBase64 = new CodeBase64(); string b64Login = codeBase64.EncodeBase64(smtpMessage.Username); string b64Password = codeBase64.EncodeBase64(smtpMessage.Password); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(_serverAddress, 587); socket.ReceiveTimeout = 1000; string outputString; socket.Send(Encoding.UTF8.GetBytes("helo\r\n")); socket.Send(Encoding.UTF8.GetBytes("auth login\r\n")); outputString = GetCurrentSocketInfo(socket); socket.Send(Encoding.UTF8.GetBytes(b64Login + "\r\n")); outputString = GetCurrentSocketInfo(socket); socket.Send(Encoding.UTF8.GetBytes(b64Password + "\r\n")); outputString = GetCurrentSocketInfo(socket); socket.Send(Encoding.UTF8.GetBytes("mail from:<" + smtpMessage.Username + "@o2.pl>\n")); outputString = GetCurrentSocketInfo(socket); if (outputString.Contains("250") || outputString.Contains("235")) { socket.Send(Encoding.UTF8.GetBytes("rcpt to:<" + smtpMessage.TargetAddress + ">\n")); outputString = GetCurrentSocketInfo(socket); socket.Send(Encoding.UTF8.GetBytes("DATA\r\n")); outputString = GetCurrentSocketInfo(socket); socket.Send(Encoding.UTF8.GetBytes("From:<" + smtpMessage.Username + ">\n" + "To:<" + smtpMessage.TargetAddress + ">\nSubject:" + smtpMessage.Subject + "\nContent:<" + smtpMessage.Message + "\r\n.\n")); outputString = GetCurrentSocketInfo(socket); if (outputString.Contains("250")) { return(true); } } return(false); }