当前位置: 首页>>代码示例>>C#>>正文


C# Message.ToMailMessage方法代码示例

本文整理汇总了C#中OpenPop.Mime.Message.ToMailMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Message.ToMailMessage方法的具体用法?C# Message.ToMailMessage怎么用?C# Message.ToMailMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Mime.Message的用法示例。


在下文中一共展示了Message.ToMailMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FetchAllUnreadMessages

        /// <summary>
        /// gets all unread email from Gmail and returns a List of System.Net.Email.MailMessage Objects
        /// </summary>
        /// <param name="username">Gmail Login</param>
        /// <param name="password">mail Password</param>
        public static List<MailMessage> FetchAllUnreadMessages(string username, string password)
        {
            List<MailMessage> mlist = new List<MailMessage>();
            // The client disconnects from the server when being disposed

            try
            {
                using (Pop3Client client = new Pop3Client())
                {
                    // Connect to the server
                    client.Connect("pop.gmail.com", 995, true);

                    // Authenticate ourselves towards the server
                    client.Authenticate(username, password);

                    // Get the number of messages in the inbox
                    int messageCount = client.GetMessageCount();





                    for (int x = messageCount; x > 0; x--)
                    {

                        Message m = new Message(client.GetMessage(x).RawMessage);
                        System.Net.Mail.MailMessage mm = m.ToMailMessage();

                        mlist.Add(mm);

                    }
                    return mlist;
                }
            }
            catch { return mlist; }
        }
开发者ID:sanyaade-fintechnology,项目名称:NinjaTrader,代码行数:41,代码来源:Gmail.cs

示例2: TestToMailMessageDoesNotOverrideBodyWhenTwoPlainTextVersion

        public void TestToMailMessageDoesNotOverrideBodyWhenTwoPlainTextVersion()
        {
            const string multiPartMessage =
                "MIME-Version: 1.0\r\n" +
                "Content-Type: multipart/mixed;\r\n" +
                "\t\t\t\t\t\t boundary=unique-boundary-1\r\n" +
                "\r\n" +
                "This is the preamble area of a multipart message.\r\n" +
                "--unique-boundary-1\r\n" +
                "\r\n" +
                " ... Some text appears here ...\r\n" +
                "--unique-boundary-1\r\n" +
                "Content-type: text/plain; charset=US-ASCII\r\n" +
                "\r\n" +
                "This could have been part of the previous part, but\r\n" +
                "illustrates explicit versus implicit typing of body\r\n" +
                "parts.\r\n" +
                "--unique-boundary-1--\r\n";

            Message message = new Message(Encoding.ASCII.GetBytes(multiPartMessage));
            MailMessage mailMessage = message.ToMailMessage();

            Assert.NotNull(mailMessage);

            // Get the first plain text message part
            MessagePart firstPlainText = message.MessagePart.MessageParts[0];
            Assert.AreEqual(firstPlainText.GetBodyAsText(), mailMessage.Body);

            // Get the scond plain text message part
            MessagePart secondPlainText = message.MessagePart.MessageParts[1];

            // The second plain text version should be in the alternative views collection
            Assert.AreEqual(1, mailMessage.AlternateViews.Count);
            Assert.AreEqual(secondPlainText.GetBodyAsText(), Encoding.ASCII.GetString(getAttachmentBytes(mailMessage.AlternateViews[0])));
        }
开发者ID:bitspill,项目名称:Gridcoin-master,代码行数:35,代码来源:ToMailMessageTests.cs

示例3: HandleSmtpTransaction

	    /// <summary>
	    /// Handle an SMTP transaction, i.e. all activity between initial connect and QUIT command.
	    /// </summary>
	    /// <param name="output">output stream</param>
	    /// <param name="input">input stream</param>
	    /// <param name="messageQueue">The message queue to add any messages to</param>
	    /// <returns>List of received SmtpMessages</returns>
        private void HandleSmtpTransaction(StreamWriter output, TextReader input)
		{
			// Initialize the state machine
			SmtpState smtpState = SmtpState.CONNECT;
			SmtpRequest smtpRequest = new SmtpRequest(SmtpActionType.CONNECT, String.Empty, smtpState);

			// Execute the connection request
			SmtpResponse smtpResponse = smtpRequest.Execute();

			// Send initial response
			SendResponse(output, smtpResponse);
			smtpState = smtpResponse.NextState;

			SmtpMessage msg = new SmtpMessage();
            
			while (smtpState != SmtpState.CONNECT)
			{
				string line = input.ReadLine();

				if (line == null)
				{
					break;
				}

				// Create request from client input and current state
				SmtpRequest request = SmtpRequest.CreateRequest(line, smtpState);
				// Execute request and create response object
				SmtpResponse response = request.Execute();
				// Move to next internal state
				smtpState = response.NextState;
				// Store input in message
				msg.Store(response, request.Params);

				// If message reception is complete save it
				if (smtpState == SmtpState.QUIT)
				{
                    // Remove the last carriage return and new line
                    string mimeMessage = msg.RawMessage;
                    byte[] messageBytes = Encoding.ASCII.GetBytes(mimeMessage);
                    Message message = new Message(messageBytes, true);

                    _receivedMail.Enqueue(message.ToMailMessage());

					msg = new SmtpMessage();
                }

                // Send reponse to client after we have stored the email, so when asking for the recived mail list it will be there 
                // (this was not the way it was done before)
                SendResponse(output, response);

			}
		}
开发者ID:TheSpider,项目名称:nDumbster,代码行数:59,代码来源:SimpleSmtpServer.cs

示例4: GetMailMessageFromMessage

        private MailMessage GetMailMessageFromMessage(Message msg)
        {
            var mailMessage = msg.ToMailMessage();
            mailMessage.Attachments.Clear();

            var attachParts = msg.FindAllAttachments();
            foreach (var part in attachParts)
            {
                var attachment = new System.Net.Mail.Attachment(new MemoryStream(part.Body), part.FileName, part.ContentType.MediaType);
                mailMessage.Attachments.Add(attachment);
            }

            return mailMessage;
        }
开发者ID:feafarot,项目名称:fMailer,代码行数:14,代码来源:DistributionsDomainController.cs


注:本文中的OpenPop.Mime.Message.ToMailMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。