コード例 #1
0
ファイル: SmtpClient.cs プロジェクト: c0d3l0g1c/Skycap-Mail
        public virtual SendResult SendOne(string addressFrom, string addressTo, string messageSubject, string messageText)
        {
            EmailAddress from    = new EmailAddress(addressFrom);
            EmailAddress to      = new EmailAddress(addressTo);
            SmtpMessage  message = new SmtpMessage(from, to, messageSubject, messageText);

            return(this.SendOne(message));
        }
コード例 #2
0
 /// <summary>
 /// Returns encoded message as iterator of strings
 ///
 /// </summary>
 /// <param name="message">Message to encode</param>
 /// <returns>
 /// Iterator through encoded strings, that are ready to sent to smtp server
 /// </returns>
 /// <exception cref="T:System.ArgumentNullException">The message argument cannot be null</exception>
 public static IEnumerable <string> GetEncoded(SmtpMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     else
     {
         return(MailMessageRFCEncoder.GetEncoded(message, message.TextEncoding));
     }
 }
コード例 #3
0
ファイル: SmtpClient.cs プロジェクト: c0d3l0g1c/Skycap-Mail
        public virtual SendResult SendOne(SmtpMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            List <SmtpMessage> messages = new List <SmtpMessage> {
                message
            };

            return(this.SendSome(messages)[0]);
        }
コード例 #4
0
ファイル: SmtpClient.cs プロジェクト: c0d3l0g1c/Skycap-Mail
        public virtual IAsyncResult BeginSendOne(SmtpMessage message, AsyncCallback callback)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            List <SmtpMessage> list = new List <SmtpMessage> {
                message
            };
            SendOneDelegate delegate2 = new SendOneDelegate(this.SendOne);

            return(delegate2.BeginInvoke(message, callback, this));
        }
コード例 #5
0
ファイル: SmtpClient.cs プロジェクト: c0d3l0g1c/Skycap-Mail
        public virtual SendResult SendOne(string addressFrom, IEnumerable <string> addressTo, string messageSubject, string messageText)
        {
            EmailAddress           from = new EmailAddress(addressFrom);
            EmailAddressCollection to   = new EmailAddressCollection();

            foreach (string str in addressTo)
            {
                to.Add(new EmailAddress(str));
            }
            SmtpMessage message = new SmtpMessage(from, to, messageSubject, messageText);

            return(this.SendOne(message));
        }
コード例 #6
0
        /// <summary>
        /// Returns encoded message as iterator of strings
        ///
        /// </summary>
        /// <param name="message">Message to encode</param><param name="encoding">Encoding of text part to use</param>
        /// <returns>
        /// Iterator through encoded strings, that are ready to sent to smtp server
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">Neither argument can be null</exception><exception cref="T:System.InvalidOperationException">HTML content type is specified, but PlainText field is not initialized</exception><exception cref="T:System.NotSupportedException">Only PlainText and HTML content type is supported</exception>
        public static IEnumerable <string> GetEncoded(SmtpMessage message, Encoding encoding)
        {
            // ISSUE: fault handler
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }
            yield return("MIME-Version: 1.0");

            yield return(string.Format("From:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddress(message.From, encoding, 76 - "From:".Length)));

            if (message.Sender != null)
            {
                yield return(string.Format("Sender:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddress(message.Sender, encoding, 76 - "Sender:".Length)));
            }
            if (message.ReplyTo.Count > 0)
            {
                yield return(string.Format("Reply-To:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.ReplyTo, encoding, 76 - "Reply-To:".Length)));
            }
            if (message.To.Count > 0)
            {
                yield return(string.Format("To:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.To, encoding, 76 - "To:".Length)));
            }
            if (message.CarbonCopies.Count > 0)
            {
                yield return(string.Format("Cc:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.CarbonCopies, encoding, 76 - "Cc:".Length)));
            }
            yield return(string.Format("Subject:{0}", (object)MailMessageRFCEncoder.MimeEncodeHeader(message.Subject, 76, 76 - "Subject:".Length, encoding)));

            if (message.Date != DateTime.MinValue)
            {
                yield return(string.Format("Date:{0}", (object)message.Date.ToUniversalTime().ToString("r")));
            }
            else
            {
                yield return(string.Format("Date:{0}", (object)DateTime.UtcNow.ToUniversalTime().ToString("r")));
            }
            if (!string.IsNullOrEmpty(message.InReplyTo))
            {
                yield return(string.Format("In-Reply-To:{0}", (object)message.InReplyTo));
            }
            if (!string.IsNullOrEmpty(message.References))
            {
                yield return(string.Format("References:{0}", (object)message.References));
            }
            if (message.ResentDate != DateTime.MinValue)
            {
                yield return(string.Format("Resent-Date:{0}", (object)message.ResentDate.ToUniversalTime().ToString("r")));
            }
            if (message.ResentFrom != null)
            {
                yield return(string.Format("Resent-From:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddress(message.ResentFrom, encoding, 76 - "Resent-From:".Length)));
            }
            if (message.ResentSender != null)
            {
                yield return(string.Format("Resent-Sender:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddress(message.ResentSender, encoding, 76 - "Resent-Sender:".Length)));
            }
            if (message.ResentTo != null && message.ResentTo.Count > 0)
            {
                yield return(string.Format("Resent-To:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.ResentTo, encoding, 76 - "Resent-To:".Length)));
            }
            if (message.ResentCarbonCopies != null && message.ResentCarbonCopies.Count > 0)
            {
                yield return(string.Format("Resent-Cc:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.ResentCarbonCopies, encoding, 76 - "Resent-Cc:".Length)));
            }
            if (message.ResentBlindedCarbonCopies != null && message.ResentBlindedCarbonCopies.Count > 0)
            {
                yield return(string.Format("Resent-Bcc:{0}", (object)MailMessageRFCEncoder.EncodeEmailAddressCollection((IEnumerable <EmailAddress>)message.ResentBlindedCarbonCopies, encoding, 76 - "Resent-Bcc:".Length)));
            }
            if (!string.IsNullOrEmpty(message.ResentMessageID))
            {
                yield return(string.Format("Resent-Message-ID:{0}", (object)message.ResentMessageID));
            }
            if (!string.IsNullOrEmpty(message.Comments))
            {
                yield return(string.Format("Comments:{0}", (object)MailMessageRFCEncoder.MimeEncodeHeader(message.Comments, 76, 76 - "Comments:".Length, encoding)));
            }
            if (message.Keywords != null && message.Keywords.Count > 0)
            {
                yield return(string.Format("Keywords:{0}", (object)MailMessageRFCEncoder.MimeEncodeHeader(MailMessageRFCEncoder.StringJoin((IEnumerable <string>)message.Keywords, ", "), 76, 76 - "Keywords:".Length, encoding)));
            }
            IEnumerator <KeyValuePair <string, string> > enumerator1 = message.ExtraHeaders.GetEnumerator();

            while (enumerator1.MoveNext())
            {
                KeyValuePair <string, string> pair = enumerator1.Current;
                yield return(string.Format("{0}: {1}", (object)pair.Key, (object)pair.Value));
            }
            if (enumerator1 != null)
            {
                enumerator1.Dispose();
            }
            if (message.Attachments.Count > 0)
            {
                Guid boundaryId = Guid.NewGuid();
                yield return(string.Format("Content-Type: multipart/mixed; boundary=\"{0}\"", (object)boundaryId));

                yield return("");

                yield return(string.Format("--{0}", (object)boundaryId));

                IEnumerator <string> enumerator2 = MailMessageRFCEncoder.EncodeMessageText((MailMessage)message, encoding).GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    string str = enumerator2.Current;
                    yield return(str);
                }
                if (enumerator2 != null)
                {
                    enumerator2.Dispose();
                }
                IEnumerator <Attachment> enumerator3 = message.Attachments.GetEnumerator();
                while (enumerator3.MoveNext())
                {
                    Attachment attachment = enumerator3.Current;
                    yield return("");

                    yield return(string.Format("--{0}", (object)boundaryId));

                    yield return(string.Format("Content-Type: {0}; name=\"{1}\"", (object)(attachment.ContentType.Type + "/" + attachment.ContentType.SubType), (object)attachment.TransferFilename));

                    yield return(string.Format("Content-Disposition: attachment; filename=\"{0}\"", (object)attachment.TransferFilename));

                    yield return("Content-Transfer-Encoding: base64");

                    yield return("");

                    IEnumerator <string> enumerator4 = MailMessageRFCEncoder.Base64EncodeAttachment(attachment).GetEnumerator();
                    while (enumerator4.MoveNext())
                    {
                        string line = enumerator4.Current;
                        yield return(line);
                    }
                    if (enumerator4 != null)
                    {
                        enumerator4.Dispose();
                    }
                }
                if (enumerator3 != null)
                {
                    enumerator3.Dispose();
                }
                yield return("");

                yield return(string.Format("--{0}--", (object)boundaryId.ToString()));
            }
            else
            {
                IEnumerator <string> enumerator2 = MailMessageRFCEncoder.EncodeMessageText((MailMessage)message, encoding).GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    string str = enumerator2.Current;
                    yield return(str);
                }
                if (enumerator2 != null)
                {
                    enumerator2.Dispose();
                }
            }
        }