private SmtpResponseReader SendSenders(Message message) { SmtpResponseReader reader = null; foreach (var from in message.From) { var text = string.Format("MAIL FROM:<{0}>", from.Address.FullAddress); var command = new SmtpCommand(text); reader = SendAndReceive(command); if (reader.IsFatalOrErroneous) { return(reader); } } return(reader); }
/// <summary> /// Cram-MD5 authorization. /// http://tools.ietf.org/html/rfc2195 /// </summary> private bool AuthenticateCramMd5(NetworkCredential credentials) { var command = new SmtpCommand("AUTH CRAM-MD5"); var response = _client.SendAndReceive(command); var base64 = response.CurrentLine.Substring(4).TrimEnd(); var challenge = Base64Encoder.Decode(base64, Encoding.UTF8); var username = credentials.UserName; var password = credentials.Password; var hash = CramMd5Hasher.ComputeHash(password, challenge); var authentication = username + " " + hash; var reader = _client.SendAndReceive(new SmtpCommand(Base64Encoder.Encode(authentication))); return(reader.IsOk); }
private SmtpResponseReader SendData(Message message) { SendAndReceive(new SmtpCommand("DATA")); var mime = message.ToMime(); using (var reader = new StringReader(mime)) { var chunkSize = UpdateUploadProgressTriggerChunkSize.Bytes; var trigger = chunkSize; var current = 0; var total = mime.Length; var command = new SmtpCommand(string.Empty); while (true) { var line = reader.ReadLine(); if (line == null) { break; } command.Text = StuffPeriodIfNecessary(line); Send(command); // dont forget the newline characters current += command.Text.Length + 2; if (trigger - current < 0) { InvokeUploadProgressChanged(current, total); trigger += chunkSize; } if (current >= total) { InvokeUploadProgressChanged(total, total); } } SendDataTermination(); } return(Receive()); }
private SmtpServerCapability Hello() { var host = Dns.GetHostName(); var command = new SmtpCommand("EHLO " + host); Send(command); // Timeout suggestion // http://tools.ietf.org/html/rfc5321#section-4.5.3.2.1 var timeout = TimeSpan.FromMinutes(5); var response = Receive(timeout); // fallback to HELO if EHLO is not supported if (response.IsFatalOrErroneous) { command = new SmtpCommand("HELO " + host); Send(command); response = Receive(timeout); } return(StaticResponseParser.ParseCapability(response)); }
/// <summary> /// Login authorization, same as plain but split into two separate command/responses. /// http://tools.ietf.org/html/rfc4616 /// </summary> private bool AuthenticateLogin(NetworkCredential credentials) { var command = new SmtpCommand("AUTH LOGIN"); var response = _client.SendAndReceive(command); if (response.ResponseCode != 334) { return(false); } var username = Base64Encoder.Encode(credentials.UserName); var userNameResponse = _client.SendAndReceive(new SmtpCommand(username)); if (userNameResponse.ResponseCode != 334) { return(false); } var password = Base64Encoder.Encode(credentials.Password); var passwordResponse = _client.SendAndReceive(new SmtpCommand(password)); return(passwordResponse.ResponseCode == ResponseCodes.AuthenticationSuccessful); }
private SmtpResponseReader SendRecipients(Message message) { SmtpResponseReader reader = null; var recipients = new List <EmailContact>(); recipients.AddRange(message.Ccs); recipients.AddRange(message.Bccs); recipients.AddRange(message.To); recipients.RemoveDuplicates(); foreach (var recipient in recipients) { var text = string.Format("RCPT TO:<{0}>", recipient.Address.FullAddress); var command = new SmtpCommand(text); reader = SendAndReceive(command); if (reader.IsFatalOrErroneous) { return(reader); } } return(reader); }
private SmtpResponseReader SendData(Message message) { SendAndReceive(new SmtpCommand("DATA")); var mime = message.ToMime(); using (var reader = new StringReader(mime)) { var chunkSize = UpdateUploadProgressTriggerChunkSize.Bytes; var trigger = chunkSize; var current = 0; var total = mime.Length; var command = new SmtpCommand(string.Empty); while (true) { var line = reader.ReadLine(); if (line == null) { break; } command.Text = StuffPeriodIfNecessary(line); Send(command); // dont forget the newline characters current += command.Text.Length + 2; if (trigger - current < 0) { InvokeUploadProgressChanged(current, total); trigger += chunkSize; } if (current >= total) { InvokeUploadProgressChanged(total, total); } } SendDataTermination(); } return Receive(); }
private SmtpServerCapability Hello() { var host = Dns.GetHostName(); var command = new SmtpCommand("EHLO " + host); Send(command); // Timeout suggestion // http://tools.ietf.org/html/rfc5321#section-4.5.3.2.1 var timeout = TimeSpan.FromMinutes(5); var response = Receive(timeout); // fallback to HELO if EHLO is not supported if (response.IsFatalOrErroneous) { command = new SmtpCommand("HELO " + host); Send(command); response = Receive(timeout); } return StaticResponseParser.ParseCapability(response); }
internal SmtpResponseReader SendAndReceive(SmtpCommand command) { Send(command); return Receive(); }
internal void Send(SmtpCommand command) { WriteLine(command.Text); }
public bool AuthenticateXOAuth(string key) { var command = new SmtpCommand(string.Format("AUTH XOAUTH {0}", key)); return(_client.SendAndReceive(command).IsOk); }
/// <summary> /// Cram-MD5 authorization. /// http://tools.ietf.org/html/rfc2195 /// </summary> private bool AuthenticateCramMd5(NetworkCredential credentials) { var command = new SmtpCommand("AUTH CRAM-MD5"); var response = _client.SendAndReceive(command); var base64 = response.CurrentLine.Substring(4).TrimEnd(); var challenge = Base64Encoder.Decode(base64, Encoding.UTF8); var username = credentials.UserName; var password = credentials.Password; var hash = CramMd5Hasher.ComputeHash(password, challenge); var authentication = username + " " + hash; var reader = _client.SendAndReceive(new SmtpCommand(Base64Encoder.Encode(authentication))); return reader.IsOk; }
internal SmtpResponseReader SendAndReceive(SmtpCommand command) { Send(command); return(Receive()); }
/// <summary> /// Login authorization, same as plain but split into two separate command/responses. /// http://tools.ietf.org/html/rfc4616 /// </summary> private bool AuthenticateLogin(NetworkCredential credentials) { var command = new SmtpCommand("AUTH LOGIN"); var response = _client.SendAndReceive(command); if (response.ResponseCode != 334) { return false; } var username = Base64Encoder.Encode(credentials.UserName); var userNameResponse = _client.SendAndReceive(new SmtpCommand(username)); if (userNameResponse.ResponseCode != 334) { return false; } var password = Base64Encoder.Encode(credentials.Password); var passwordResponse = _client.SendAndReceive(new SmtpCommand(password)); return passwordResponse.ResponseCode == ResponseCodes.AuthenticationSuccessful; }
private SmtpResponseReader SendRecipients(Message message) { SmtpResponseReader reader = null; var recipients = new List<EmailContact>(); recipients.AddRange(message.Ccs); recipients.AddRange(message.Bccs); recipients.AddRange(message.To); recipients.RemoveDuplicates(); foreach (var recipient in recipients) { var text = string.Format("RCPT TO:<{0}>", recipient.Address.FullAddress); var command = new SmtpCommand(text); reader = SendAndReceive(command); if (reader.IsFatalOrErroneous) { return reader; } } return reader; }
private SmtpResponseReader SendSenders(Message message) { SmtpResponseReader reader = null; foreach (var from in message.From) { var text = string.Format("MAIL FROM:<{0}>", from.Address.FullAddress); var command = new SmtpCommand(text); reader = SendAndReceive(command); if (reader.IsFatalOrErroneous) { return reader; } } return reader; }
public bool AuthenticateXOAuth(string key) { var command = new SmtpCommand(string.Format("AUTH XOAUTH {0}", key)); return _client.SendAndReceive(command).IsOk; }