Пример #1
0
        public string exportData(WebReference.AttachmentItemInfo info)
        {
            int offset = 0;

            WebReference.getAttachmentRequest  req;
            WebReference.getAttachmentResponse resp;

            String fileName = Guid.NewGuid().ToString();
            // String path = "c:\\temp\\" + info.name;
            String path = HttpContext.Current.Server.MapPath("~/TemporaryFiles/") + fileName + System.IO.Path.GetExtension(info.name);

            System.IO.FileStream   fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
            System.IO.BinaryWriter fw = new System.IO.BinaryWriter(fs);

            for (;;)
            {
                req        = new WebReference.getAttachmentRequest();
                req.id     = info.id.Value;
                req.length = 6144;
                req.offset = offset;
                resp       = ws.getAttachmentRequestMessage(req);
                if (0 != resp.status.code)
                {
                    break;
                }
                fw.Write(resp.part.Value);
                offset = resp.part.offset;
                if (0 == offset)
                {
                    break;
                }
            }
            fs.Close();
            path = path.Replace(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
            return(path);
        }
Пример #2
0
        /// <summary>
        /// Attachment should be with ABSOLUTE PATH (with AppPath())
        /// </summary
        public void SendEmail(NovellGroupWiseMail mail)
        {
            WebReference.Mail             mailToSend = new WebReference.Mail();
            WebReference.MessagePart[]    part;
            WebReference.NameAndEmail     item;
            WebReference.Recipient[]      recips;
            WebReference.sendItemRequest  req;
            WebReference.sendItemResponse resp;
            mailToSend.subject = mail.Subject;

            var att = new WebReference.AttachmentItemInfo();

            List <AttachmentItemInfo> atts = new List <AttachmentItemInfo>();



            //сохранить html text в файл text.htm
            if (mail.HtmlText != null)
            {
                String path = HttpContext.Current.Server.MapPath("~/TemporaryFiles/") + Guid.NewGuid() + ".htm";
                var    fs   = new FileStream(path, FileMode.Create);
                using (var bw = new BinaryWriter(fs))
                {
                    bw.Write(mail.HtmlText);
                }
                fs.Close();

                var fss = new FileStream(path, FileMode.OpenOrCreate);
                using (var binaryReader = new BinaryReader(fss))
                {
                    att.data = binaryReader.ReadBytes((int)fss.Length);
                }
                fss.Close();
                att.name = "text.htm";
                atts.Add(att);
            }


            if (mail.Attachments != null)
            {
                foreach (var attachment in mail.Attachments)
                {
                    var fs = new FileStream(attachment, FileMode.OpenOrCreate);
                    using (var binaryReader = new BinaryReader(fs))
                    {
                        att.data = binaryReader.ReadBytes((int)fs.Length);
                    }
                    att.name = System.IO.Path.GetFileName(attachment);
                    atts.Add(att);
                    fs.Close();
                }
            }

            mailToSend.attachments   = atts.ToArray();
            mailToSend.hasAttachment = true;

            //if (0 != mail.Text.Length)
            //{
            //    part = new WebReference.MessagePart[1];
            //    part[0] = new WebReference.MessagePart();
            //    part[0].Value = System.Text.UTF8Encoding.UTF8.GetBytes(mail.Text);
            //    mailToSend.message = part;
            //}

            recips = new WebReference.Recipient[mail.Recipients.Count];
            for (int i = 0; i < mail.Recipients.Count; i++)
            {
                recips[i]             = new WebReference.Recipient();
                recips[i].displayName = mail.Recipients[i].Name;
                recips[i].email       = mail.Recipients[i].Email;
                recips[i].uuid        = mail.Recipients[i].Id;
            }

            mailToSend.distribution            = new WebReference.Distribution();
            mailToSend.distribution.recipients = recips;

            req      = new WebReference.sendItemRequest();
            req.item = mailToSend;

            resp = ws.sendItemRequest(req);
        }