예제 #1
0
 public void Send(ChannelMessage message)
 {
     foreach (var rcpt in message.To.Union(message.CC).Union(message.BCC))
     {
         PerformRequest(
             String.Format("http://data.hyves-api.nl/?title={0}&body={1}&target_userid={2}&ha_method=messages.send&ha_version=experimental&ha_format=xml&ha_fancylayout=true",
                 message.Context,
                 message.BodyHtml.ReadString().StripHtml(),
                 rcpt.Address));
     }
 }
        public static ChannelMessage From(Stream stream, ChannelMessageHeader header)
        {
            stream.Seek(0, SeekOrigin.Begin);

            var mimeMessage = Mime.Parse(stream);
            var message = new ChannelMessage();

            if (header != null)
            {
                message.MessageNumber = header.MessageNumber;
                message.Size = header.Size;
                message.SourceFolder = header.SourceFolder;
                message.IsRead = header.IsRead;
                message.IsStarred = header.IsStarred;
                message.DateReceived = header.DateReceived;
            }
            else
            {
                message.SourceFolder = "INBOX";
                message.DateReceived = DateTime.Now;
            }

            message.Context = mimeMessage.MainEntity.Subject;
            message.MessageIdentifier = mimeMessage.MainEntity.MessageID;
            message.InReplyTo = mimeMessage.MainEntity.InReplyTo;
            message.BodyHtml = mimeMessage.BodyHtml.ToStream();

            if (!String.IsNullOrEmpty(mimeMessage.BodyText))
                message.BodyText = mimeMessage.BodyText.ToStream();

            message.From = new SourceAddress(mimeMessage.MainEntity.From.ToAddressListString());

            if (mimeMessage.MainEntity.To == null)
            {
                var deliveredTo = mimeMessage.MainEntity.Header.GetFirst("Delivered-To:");

                if (deliveredTo != null)
                    message.To = new SourceAddressCollection(deliveredTo.Value);
            }
            else
            {
                message.To = new SourceAddressCollection(mimeMessage.MainEntity.To.ToAddressListString());
            }

            if (mimeMessage.MainEntity.Cc != null)
                message.CC = new SourceAddressCollection(mimeMessage.MainEntity.Cc.ToAddressListString());

            if (mimeMessage.MainEntity.Bcc != null)
                message.BCC = new SourceAddressCollection(mimeMessage.MainEntity.Bcc.ToAddressListString());

            foreach (var att in mimeMessage.Attachments)
            {
                var attachment = new ChannelAttachment
                    {
                        Filename = att.ContentDisposition == ContentDisposition_enum.Attachment
                                 	? att.ContentDisposition_FileName
                                 	: att.ContentType_Name
                    };

                if (!String.IsNullOrEmpty(att.ContentID))
                    attachment.ContentId = att.ContentID.Trim('<', '>');

                attachment.ContentType = String.IsNullOrEmpty(att.ContentID)
                    ? ContentType.Attachment : ContentType.Inline;

                attachment.ContentStream = new MemoryStream(att.Data);

                message.Attachments.Add(attachment);
            }

            return message;
        }
예제 #3
0
        public IEnumerable<ChannelMessage> GetMessage(ChannelMessageHeader header)
        {
            ChannelMessage message = new ChannelMessage();
            message.MessageNumber = header.MessageNumber;
            message.MessageIdentifier = header.MessageIdentifier;
            message.Context = header.Context;
            message.From = header.From;
            message.To.AddRange(header.To);
            message.InReplyTo = header.InReplyTo;
            message.BodyHtml = header.Body.ToStream();
            message.DateReceived = header.DateReceived;

            yield return message;
        }
        public IEnumerable<ChannelMessage> GetMessage(ChannelMessageHeader header)
        {
            ChannelMessage message = new ChannelMessage();
            message.MessageNumber = header.MessageNumber;
            message.MessageIdentifier = header.MessageIdentifier;
            message.From = header.From;
            message.Context = header.Context;
            message.BodyText = header.Body.ToStream();
            message.IsRead = header.IsRead;
            message.DateReceived = header.DateReceived;
            message.ConversationId = header.Metadata.i2mpRelationId;

            yield return message;
        }
 public void Send(ChannelMessage message)
 {
 }
        public IEnumerable<ChannelMessage> GetMessage(ChannelMessageHeader header)
        {
            var client = new ExchangeClient(Hostname, CredentialsProvider);

            ChannelMessage message = new ChannelMessage();
            MessageType inboxItem = client.GetMessage(header.MessageNumber);

            // Now the message Body is there.
            BodyType messageBody = inboxItem.Body;

            message.Size = header.Size;
            message.MessageNumber = header.MessageNumber;
            message.MessageIdentifier = header.MessageIdentifier;
            message.Context = header.Context;
            message.From = new SourceAddress(inboxItem.From.Item.EmailAddress, inboxItem.From.Item.Name);

            if (inboxItem.ToRecipients != null)
                foreach (var toRecipient in inboxItem.ToRecipients)
                    message.To.Add(new SourceAddress(toRecipient.EmailAddress, toRecipient.Name));

            if (inboxItem.CcRecipients != null)
                foreach (var ccRecipient in inboxItem.CcRecipients)
                    message.CC.Add(new SourceAddress(ccRecipient.EmailAddress, ccRecipient.Name));

            if (inboxItem.BccRecipients != null)
                foreach (var bccRecipient in inboxItem.BccRecipients)
                    message.BCC.Add(new SourceAddress(bccRecipient.EmailAddress, bccRecipient.Name));

            message.InReplyTo = inboxItem.InReplyTo;
            message.Metadata = header.Metadata;
            message.IsRead = inboxItem.IsRead;
            message.BodyHtml = messageBody.Value.ToStream();
            message.DateReceived = header.DateReceived;

            if (inboxItem.Attachments != null)
            {
                foreach (AttachmentType exchAttachment in inboxItem.Attachments)
                {
                    var fileAttachment = client.GetAttachment(exchAttachment.AttachmentId.Id);

                    message.Attachments.Add(new ChannelAttachment
                     	{
                     		Filename = fileAttachment.Name,
                     		ContentType = ContentType.Attachment,
                     		ContentStream = new MemoryStream(fileAttachment.Content)
                     	});
                }
            }

            yield return message;
        }
        public void Send(ChannelMessage message)
        {
            var client = new ExchangeClient(Hostname, CredentialsProvider);

            var messageId = client.SaveMessage(message);

            // Upload attachments
            if (message.Attachments.Count > 0)
                client.SaveAttachments(messageId, message);

            // Refresh and send message by message-id
            client.SendMessage(client.GetMessageId(messageId.Id).ItemId);
        }
예제 #8
0
        void SendCloudMessage(ChannelConfiguration channel, ChannelMessage message)
        {
            var data = String.Format("wrap_access_token={0}&targetchannelkey={1}&from={2}&to={3}&cc={4}&bcc={5}&subject={6}&inreplyto={7}&conversationidentifier={8}&body={9}",
                CloudApi.AccessToken,
                channel.ChannelKey,
                HttpUtility.UrlEncode(message.From.ToString()),
                HttpUtility.UrlEncode(message.To.ToString()),
                HttpUtility.UrlEncode(message.CC.ToString()),
                HttpUtility.UrlEncode(message.BCC.ToString()),
                HttpUtility.UrlEncode(message.Context),
                HttpUtility.UrlEncode(message.InReplyTo),
                HttpUtility.UrlEncode(message.ConversationId),
                HttpUtility.UrlEncode(message.BodyHtml.ReadString()));

            string messageKey;

            if (message.Attachments.Count > 0)
            {
                var files = message.Attachments
                    .Select(s => new UploadFile(s.ContentStream, s.Filename, "application/octet-stream"))
                    .ToList();

                messageKey = HttpServiceRequest.Post(String.Concat(CloudApi.ApiBaseUrl, "send/message"), data, files, true);
            }
            else
            {
                messageKey = HttpServiceRequest.Post(String.Concat(CloudApi.ApiBaseUrl, "send/message"), data, true);
            }

            // Update messagekey
            this.message.MessageKey = messageKey;

            ClientState.Current.DataService.Update(this.message);
        }
예제 #9
0
        public void Send(ChannelMessage message)
        {
            var creds = CredentialsProvider.GetCredentials().ToNetworkCredential();

            Mail_Message msg = new Mail_Message();

            msg.MimeVersion = "1.0";
            msg.MessageID = MIME_Utils.CreateMessageID();
            msg.Subject = message.Context;
            msg.From = message.From.ToMailBoxList();
            msg.ReplyTo = message.ReturnTo == null ?
                message.From.ToAddressList() : message.ReturnTo.ToAddressList();

            if (String.IsNullOrEmpty(message.InReplyTo) == false)
                msg.InReplyTo = message.InReplyTo;

            msg.To = new Mail_t_AddressList();
            foreach (var address in message.To)
                msg.To.Add(address.ToMailBox());

            msg.Cc = new Mail_t_AddressList();
            foreach (var address in message.CC)
                msg.Cc.Add(address.ToMailBox());

            //--- multipart/mixed -------------------------------------------------------------------------------------------------
            MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed);
            contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
            MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed);
            msg.Body = multipartMixed;

            //--- multipart/alternative -----------------------------------------------------------------------------------------
            MIME_Entity entity_multipartAlternative = new MIME_Entity();
            MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);
            contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');
            MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);
            entity_multipartAlternative.Body = multipartAlternative;
            multipartMixed.BodyParts.Add(entity_multipartAlternative);

            //--- text/plain ----------------------------------------------------------------------------------------------------
            MIME_Entity entity_text_plain = new MIME_Entity();
            MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);
            entity_text_plain.Body = text_plain;
            // Add text body if there is any
            if (message.BodyText != null && message.BodyText.Length > 0)
            {
                var bodyText = message.BodyText.ReadString();

                // Make sure there is a newline at the end of our text, otherwise it will screw up
                // our multipart data format
                if (!bodyText.EndsWith(Environment.NewLine))
                    bodyText = bodyText + Environment.NewLine;

                text_plain.SetText(MIME_TransferEncodings.SevenBit, Encoding.UTF8, bodyText);
            }

            multipartAlternative.BodyParts.Add(entity_text_plain);

            //--- text/html ------------------------------------------------------------------------------------------------------
            MIME_Entity entity_text_html = new MIME_Entity();
            MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);
            entity_text_html.Body = text_html;
            if (message.BodyHtml != null && message.BodyHtml.Length > 0)
            {
                var bodyHtml = message.BodyHtml.ReadString();

                // Make sure there is a newline at the end of our text, otherwise it will screw up
                // our multipart data format
                if (!bodyHtml.EndsWith(Environment.NewLine))
                    bodyHtml = bodyHtml + Environment.NewLine;

                text_html.SetText(MIME_TransferEncodings.SevenBit, Encoding.UTF8, bodyHtml);
            }

            multipartAlternative.BodyParts.Add(entity_text_html);

            foreach (var channelAttachment in message.Attachments)
            {
                MIME_b_Application attachmentBody = new MIME_b_Application(MIME_MediaTypes.Application.octet_stream);
                MIME_Entity attachment = new MIME_Entity();
                attachment.Body = attachmentBody;

                // Has to happen before the following lines of code
                multipartMixed.BodyParts.Add(attachment);

                attachment.ContentType = new MIME_h_ContentType(MimeHelper.GetMimeType(channelAttachment.Filename));
                attachment.ContentType.Param_Name = channelAttachment.Filename;

                MIME_h_ContentDisposition contentDisposition = new MIME_h_ContentDisposition(DispositionTypeNames.Attachment);
                contentDisposition.Param_FileName = channelAttachment.Filename;

                attachment.ContentDisposition = contentDisposition;
                attachment.ContentTransferEncoding = TransferEncoding.Base64.ToString();

                attachmentBody.SetData(channelAttachment.ContentStream, MIME_TransferEncodings.Base64);
            }

            // Inject headers
            if (!String.IsNullOrEmpty(message.MessageIdentifier))
                msg.Header.Add(new MIME_h_Unstructured("x-i2mp-messageid", message.MessageIdentifier));

            //if (!String.IsNullOrEmpty(message.Metadata.i2mpFlow))
            //    msg.Header.Add(new MIME_h_Unstructured("x-i2mp-flow", message.Metadata.i2mpFlow));

            //if (!String.IsNullOrEmpty(message.Metadata.i2mpReference))
            //    mailMessage.Headers.Add("X-i2mp-ref", message.Metadata.i2mpReference);

            //if (!String.IsNullOrEmpty(message.Metadata.i2mpSequence))
            //    mailMessage.Headers.Add("X-i2mp-seq", message.Metadata.i2mpSequence);

            //if (!String.IsNullOrEmpty(message.Metadata.i2mpRelation))
            //    mailMessage.Headers.Add("X-i2mp-rel", message.Metadata.i2mpRelation);

            //if (!String.IsNullOrEmpty(message.Metadata.i2mpRelationId))
            //    mailMessage.Headers.Add("X-i2mp-rel-id", message.Metadata.i2mpRelationId);

            // Send message
            try
            {
                SMTP_Client client = new SMTP_Client();

                if ("/Settings/Channels/LoggerEnabled".AsKey(false))
                    client.Logger = new LumiSoft.Net.Log.Logger();

                // todo push this logic into the smtp client implementation itself
                if (Hostname == "smtp.live.com")
                {
                    // Hack for hotmail, first do a connect with no secured channel,
                    // then a STARTTLS
                    client.Connect(Hostname, Port, false);
                    client.StartTLS();
                }
                else
                {
                    client.Connect(Hostname, Port, IsSecured);
                }

                client.Authenticate(creds.UserName, creds.Password);

                using (MemoryStream ms = new MemoryStream())
                {
                    client.MailFrom(msg.From[0].Address, -1);

                    msg.ToStream(ms,
                        new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);

                    // Reset stream
                    ms.Seek(0, SeekOrigin.Begin);

                    foreach (var address in message.To)
                        client.RcptTo(address.Address);

                    foreach (var address in message.CC)
                        client.RcptTo(address.Address);

                    foreach (var address in message.BCC)
                        client.RcptTo(address.Address);

                    try
                    {
                        client.SendMessage(ms);
                    }
                    finally
                    {
                        client.Dispose();
                    }
                }
            }
            catch(SmtpFailedRecipientsException e)
            {
                throw new ChannelFunctionalException(e.Message, e) { DoNotRetry = true };
            }
            catch (SmtpException e)
            {
                throw new ChannelFunctionalException(e.Message, e);
            }
            catch (Exception e)
            {
                throw new ChannelFunctionalException(e.Message, e);
            }
        }
예제 #10
0
        public void Send(ChannelMessage message)
        {
            var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            foreach (var singleToName in message.To)
            {
                service.SendDirectMessage(Int32.Parse(singleToName.Address), message.BodyText.ReadString());
            }
        }
예제 #11
0
        /// <summary>
        /// Saves the given message to the drafts folder.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public ItemIdType SaveMessage(ChannelMessage message)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            var createItemRequest = new CreateItemType();

            // Indicate that we want to save only at first
            createItemRequest.MessageDisposition = MessageDispositionType.SaveOnly;
            createItemRequest.MessageDispositionSpecified = true;
            createItemRequest.Items = new NonEmptyArrayOfAllItemsType();

            // Create a single e-mail message.
            var exchMessage = new MessageType();
            exchMessage.Subject = message.Context;
            exchMessage.Body = new BodyType { BodyType1 = BodyTypeType.HTML, Value = message.BodyHtml.ReadString() };
            exchMessage.ItemClass = "IPM.Note";
            exchMessage.Sender = new SingleRecipientType();
            exchMessage.Sender.Item = new EmailAddressType { EmailAddress = message.From.Address };

            exchMessage.ToRecipients = new EmailAddressType[message.To.Count];
            exchMessage.CcRecipients = new EmailAddressType[message.CC.Count];
            exchMessage.BccRecipients = new EmailAddressType[message.BCC.Count];

            for (int i = 0; i < message.To.Count; i++)
                exchMessage.ToRecipients[i] = new EmailAddressType { EmailAddress = message.To[i].Address };

            for (int i = 0; i < message.CC.Count; i++)
                exchMessage.CcRecipients[i] = new EmailAddressType { EmailAddress = message.CC[i].Address };

            for (int i = 0; i < message.BCC.Count; i++)
                exchMessage.BccRecipients[i] = new EmailAddressType { EmailAddress = message.BCC[i].Address };

            exchMessage.Sensitivity = SensitivityChoicesType.Normal;

            // Add the message to the array of items to be created.
            createItemRequest.Items.Items = new ItemType[1];
            createItemRequest.Items.Items[0] = exchMessage;

            // Send the request to create and send the e-mail item, and get the response.
            CreateItemResponseType createItemResponse = binding.CreateItem(createItemRequest);

            // Determine whether the request was a success.
            if (createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                throw new Exception(createItemResponse.ResponseMessages.Items[0].MessageText);

            return ((ItemInfoResponseMessageType)createItemResponse.ResponseMessages.Items[0]).Items.Items[0].ItemId;
        }
예제 #12
0
        /// <summary>
        /// Saves all attachments belonging to a specific message. This method can only be called after the message
        /// has been saved in exchange.
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public IEnumerable<ItemIdType> SaveAttachments(ItemIdType messageId, ChannelMessage message)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Create add attachment request.
            var attachementRequest = new CreateAttachmentType();
            attachementRequest.ParentItemId = messageId;
            attachementRequest.Attachments = new AttachmentType[message.Attachments.Count];

            for (int i = 0; i < message.Attachments.Count; i++)
            {
                var channelAttachment = message.Attachments[i];
                var exchAttachment = new FileAttachmentType();

                exchAttachment.Name = channelAttachment.Filename;
                exchAttachment.ContentType = MimeHelper.GetMimeType(channelAttachment.Filename);
                exchAttachment.Content = channelAttachment.ContentStream.GetBytes();

                attachementRequest.Attachments[i] = exchAttachment;

                var saveAttachmentResponse = binding.CreateAttachment(attachementRequest);

                // Determine whether the request was a success.
                if (saveAttachmentResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                    throw new Exception(saveAttachmentResponse.ResponseMessages.Items[0].MessageText);

                AttachmentIdType attachmentId = ((AttachmentInfoResponseMessageType)saveAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].AttachmentId;

                yield return new ItemIdType { ChangeKey = attachmentId.RootItemChangeKey, Id = attachmentId.RootItemId };
            }
        }