public void SendMail(string mailHost, string from, string to, string subject, string body, List <AttachementInfo> attachments)
    {
        SmtpClient  client  = new SmtpClient(mailHost, 25);
        MailAddress afrom   = new MailAddress(from, "RichEditClient", System.Text.Encoding.UTF8);
        MailAddress ato     = new MailAddress(to);
        MailMessage message = new MailMessage(from, to);

        message.Subject = subject;

        AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, Encoding.UTF8, MediaTypeNames.Text.Html);

        for (int i = 0; i < attachments.Count; i++)
        {
            AttachementInfo info     = attachments[i];
            LinkedResource  resource = new LinkedResource(new MemoryStream(info.Data), info.MimeType);
            resource.ContentId = info.ContentId;
            htmlView.LinkedResources.Add(resource);
        }

        message.AlternateViews.Add(htmlView);
        message.IsBodyHtml = true;

        // Specify your login/password to log on to the SMTP server, if required
        //client.Credentials = new System.Net.NetworkCredential("login", "password");

        client.Send(message);
    }
            public string CreateImageUri(string rootUri, OfficeImage image, string relativeUri)
            {
                string imageName = String.Format("image{0}", imageId);

                imageId++;

                OfficeImageFormat imageFormat      = GetActualImageFormat(image.RawFormat);
                Stream            stream           = new MemoryStream(image.GetImageBytes(imageFormat));
                string            mediaContentType = OfficeImage.GetContentType(imageFormat);
                AttachementInfo   info             = new AttachementInfo(stream, mediaContentType, imageName);

                attachments.Add(info);

                return("cid:" + imageName);
            }
Ejemplo n.º 3
0
            protected internal virtual AlternateView CreateHtmlView()
            {
                control.BeforeExport += OnBeforeExport;
                string        htmlBody = control.Document.GetHtmlText(control.Document.Range, this);
                AlternateView view     = AlternateView.CreateAlternateViewFromString(htmlBody, Encoding.UTF8, MediaTypeNames.Text.Html);

                control.BeforeExport -= OnBeforeExport;

                int count = attachments.Count;

                for (int i = 0; i < count; i++)
                {
                    AttachementInfo info     = attachments[i];
                    LinkedResource  resource = new LinkedResource(info.Stream, info.MimeType);
                    resource.ContentId = info.ContentId;
                    view.LinkedResources.Add(resource);
                }
                return(view);
            }
        public string CreateImageUri(string rootUri, OfficeImage image, string relativeUri)
        {
            string imageName = string.Format("image{0}", imageId);

            imageId++;

            OfficeImageFormat imageFormat = GetActualImageFormat(image.RawFormat);

            byte[]          data             = image.GetImageBytes(imageFormat);
            string          mediaContentType = OfficeImage.GetContentType(imageFormat);
            AttachementInfo info             = new AttachementInfo()
            {
                Data      = data,
                MimeType  = mediaContentType,
                ContentId = imageName
            };

            this.Attachments.Add(info);

            return("cid:" + imageName);
        }
Ejemplo n.º 5
0
        async Task OnAttachementsRequest(ClientAttachementsRequestMessage message, ClientConnection connection)
        {
            var result         = TransactionResultTypes.Unknown;
            var userCode       = 0L;
            var attachementKey = 0;

            var container    = _chainManager.GetContainer(message.ChainId);
            var dataChain    = container?.GetDataChain(message.ChainIndex);
            var serviceChain = container?.ServiceChain;
            var service      = container?.Service;

            if (container == null || dataChain == null || serviceChain == null)
            {
                result = TransactionResultTypes.ChainNodeInvalid;
                goto end;
            }

            if (service == null)
            {
                result = TransactionResultTypes.ChainServiceUnavailable;
                goto end;
            }

            attachementKey = dataChain.AttachementKey;
            if (attachementKey < 0)
            {
                result = TransactionResultTypes.AttachementsNotAllowed;
                goto end;
            }

            Key key = null;

            if (message.KeyIndex == Protocol.CoreAccountSignKeyIndex)
            {
                var coreAccount = _chainManager.CoreChain.GetCoreAccount(message.AccountId);
                key = coreAccount?.AccountKey;
            }
            else
            {
                var chainAccount = serviceChain.GetValidServiceAccountKey(message.AccountId, message.KeyIndex, Time.Timestamp);
                key = chainAccount?.PublicKey;
            }

            if (key == null)
            {
                result = TransactionResultTypes.InvalidServiceAccountKey;
                goto end;
            }

            var attachements = message.Attachements.GetSignedItem(key);

            if (attachements == null)
            {
                result = TransactionResultTypes.InvalidSignature;
                goto end;
            }

            if (!attachements.CheckAttachements() || AttachementInfo.IsExpired(attachements))
            {
                result = TransactionResultTypes.AttachementsInvalid;
                goto end;
            }

            var valid = await service.IsValidAttachementsRequest(attachements);

            userCode = valid.UserCode;
            if (!valid.IsOK)
            {
                result = TransactionResultTypes.ChainServiceErrorResponse;
                goto end;
            }

            if (!_attachementManager.AddAttachementsRequests(attachements))
            {
                result = TransactionResultTypes.AttachementsInvalid;
                goto end;
            }

            // everything seems to be OK
            result = TransactionResultTypes.Ok;

end:
            await connection.Send(new ClientAttachementsResponseMessage(message, result, userCode, attachementKey));
        }