/// <summary> /// Create an instance of the bounce request class. /// </summary> /// <param name="emailAddress">The valid email address.</param> /// <param name="code">The STMP Error status code. Defaults to 550, Mailbox Unavailable.</param> /// <param name="error">The error description. Defaults to empty string.</param> /// <param name="createdAt">Timestamp of the bounced event. Defaults to current time UTC.</param> /// <exception cref="ArgumentNullException">The email address is a required parameter.</exception> public BounceRequest(MailAddress emailAddress, SmtpErrorCode code = SmtpErrorCode.MAILBOX_UNAVAILABLE, string error = "", Instant?createdAt = null) { this.emailAddress = emailAddress ?? throw new ArgumentNullException(nameof(emailAddress), "Address cannot be null or empty!"); this.code = code; this.error = error; if (createdAt.HasValue) { this.createdAt = createdAt.Value; } }
/// <summary> /// Reads SMTP responses through the socket and evaluate it. /// </summary> /// <param name="expectedReply">Expected SMTP reply code.</param> /// <param name="errorCode">Error code to be used in exception, when reply code do not match.</param> /// <returns>Server resposne.</returns> private string GetResponse(string expectedReply, SmtpErrorCode errorCode) { string response = GetResponse(); if (GetReplyCode(response) != expectedReply) { throw new SmtpException(response, errorCode); } return(response); }
public void BounceRequest_Should_Set_Optional_Params(string emailAddress, SmtpErrorCode code, string error, Instant createdAt) { var mailAddress = new MailAddress(emailAddress); var bounceRequest = new BounceRequest(mailAddress, code, error, createdAt); Assert.Equal(emailAddress, bounceRequest.EmailAddress.Address); Assert.Equal(code, bounceRequest.Code); Assert.Equal(error, bounceRequest.Error); }
public void With_SendException(Type sendException, SmtpErrorCode smtpErrorCode = SmtpErrorCode.UnexpectedStatusCode) { var sender = GetMailMergeSender(); var msg = GetMimeMessage(); var config = new SmtpClientConfig { MessageOutput = MessageOutput.SmtpServer, NetworkCredential = new Credential() }; sender.Config.SmtpClientConfig[0] = config; Exception exception; if (sendException == typeof(AuthenticationException)) { exception = new AuthenticationException(); } else if (sendException == typeof(SmtpCommandException)) { exception = new SmtpCommandException(smtpErrorCode, SmtpStatusCode.CommandNotImplemented, "unitTest"); } else if (sendException == typeof(SmtpProtocolException)) { exception = new SmtpProtocolException(); } else if (sendException == typeof(IOException)) { exception = new IOException(); } else if (sendException == typeof(Exception)) { exception = new Exception(); } else { throw new ArgumentOutOfRangeException(); } var smtpClient = new FakeSmtpClient { SendException = exception }; Assert.Throws(sendException, () => sender.SendMimeMessage(smtpClient, msg, config)); Assert.ThrowsAsync(sendException, async() => await sender.SendMimeMessageAsync(smtpClient, msg, config)); }
/// <summary> /// Sends SMTP command or data through the socket. /// Waits for server response and evaluate it. /// </summary> /// <param name="command">Data to be send.</param> /// <param name="expectedReply">Expected SMTP reply code.</param> /// <param name="errorCode">Error code to be used in exception, when reply code do not match.</param> /// <returns>Complete response from server.</returns> private string SendCommand(string command, string expectedReply, SmtpErrorCode errorCode) { SendCommand(command); return(GetResponse(expectedReply, errorCode)); }
/// <summary> /// Initialize instance of SmtpException. /// </summary> /// <param name="message">Message of the exception.</param> /// <param name="smtpError">Code of the exception.</param> public SmtpException(string message, SmtpErrorCode smtpError) : base(message) { this.ErrorCode = smtpError; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="SmtpCommandException"/>. /// </remarks> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param> /// <param name="mailbox">The rejected mailbox.</param> /// <param name="message">The error message.</param> internal SmtpCommandException (SmtpErrorCode code, SmtpStatusCode status, MailboxAddress mailbox, string message) : base (message) { StatusCode = (int) status; Mailbox = mailbox; ErrorCode = code; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="SmtpCommandException"/>. /// </remarks> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param>> /// <param name="message">The error message.</param> internal SmtpCommandException (SmtpErrorCode code, SmtpStatusCode status, string message) : base (message) { StatusCode = (int) status; ErrorCode = code; }
/// <summary> /// Reads SMTP responses through the socket and evaluate it. /// </summary> /// <param name="expectedReply">Expected SMTP reply code.</param> /// <param name="errorCode">Error code to be used in exception, when reply code do not match.</param> /// <returns>Server resposne.</returns> private string GetResponse(string expectedReply, SmtpErrorCode errorCode) { string response = GetResponse(); if (GetReplyCode(response) != expectedReply) throw new SmtpException(response, errorCode); return response; }
/// <summary> /// Sends SMTP command or data through the socket. /// Waits for server response and evaluate it. /// </summary> /// <param name="command">Data to be send.</param> /// <param name="expectedReply">Expected SMTP reply code.</param> /// <param name="errorCode">Error code to be used in exception, when reply code do not match.</param> /// <returns>Complete response from server.</returns> private string SendCommand(string command, string expectedReply, SmtpErrorCode errorCode) { SendCommand(command); return GetResponse(expectedReply, errorCode); }
/// <summary> /// Initialize instance of SmtpException. /// </summary> /// <param name="smtpError">Code of the exception.</param> /// <param name="innerException">Inner exception wrapped by SmtpException</param> public SmtpException(SmtpErrorCode smtpError, Exception innerException) : base(string.Empty, innerException) { this.ErrorCode = smtpError; }
public void BounceRequest_When_Converted_To_FormContent_Should_Not_Be_Empty(string emailAddress, SmtpErrorCode code, string error, Instant createdAt) { var mailAddress = new MailAddress(emailAddress); var bounceRequest = new BounceRequest(mailAddress, code, error, createdAt); var formContent = bounceRequest.ToFormContent(); Assert.NotEmpty(formContent); }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="SmtpCommandException"/>. /// </remarks> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param> /// <param name="mailbox">The rejected mailbox.</param> /// <param name="message">The error message.</param> public SmtpCommandException(SmtpErrorCode code, SmtpStatusCode status, MailboxAddress mailbox, string message) : base(message) { StatusCode = status; Mailbox = mailbox; ErrorCode = code; }
public void BounceRequest_When_Converted_To_JsonObject_Should_Not_Be_Empty(string emailAddress, SmtpErrorCode code, string error, Instant createdAt) { var mailAddress = new MailAddress(emailAddress); var bounceRequest = new BounceRequest(mailAddress, code, error, createdAt); var json = bounceRequest.ToJson(); Assert.NotEmpty(json); }
/// <summary> /// Initialize instance of SmtpException. /// </summary> /// <param name="smtpError">Code of the exception.</param> public SmtpException(SmtpErrorCode smtpError) { this.ErrorCode = smtpError; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="SmtpCommandException"/>. /// </remarks> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param>> /// <param name="message">The error message.</param> public SmtpCommandException (SmtpErrorCode code, SmtpStatusCode status, string message) : base (message) { StatusCode = status; ErrorCode = code; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param>> /// <param name="message">The error message.</param> internal SmtpCommandException(SmtpErrorCode code, SmtpStatusCode status, string message) : base(message) { StatusCode = (int)status; ErrorCode = code; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Smtp.SmtpCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="SmtpCommandException"/>. /// </remarks> /// <param name="code">The error code.</param> /// <param name="status">The status code.</param>> /// <param name="message">The error message.</param> public SmtpCommandException(SmtpErrorCode code, SmtpStatusCode status, string message) : base(message) { StatusCode = status; ErrorCode = code; }