示例#1
0
        private void ContructRawAttacments(AE.Net.Mail.MailMessage msg)
        {
            foreach (var child in StackPanelAttachments.Children)
            {
                if (child is TextBlock txtBlock)
                {
                    var fullPath = txtBlock.DataContext as string;
                    var fileName = txtBlock.Text;
                    if (fileName.IsNotEmpty() && fullPath.IsNotEmpty())
                    {
                        try
                        {
                            var bytes = File.ReadAllBytes(fullPath);

                            var attachment = new AE.Net.Mail.Attachment(
                                bytes,
                                System.Web.MimeMapping.GetMimeMapping(fileName),
                                fileName,
                                true);

                            msg.Attachments.Add(attachment);
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                        }
                    }
                }
            }
        }
示例#2
0
        public void DoFormatMail(Mail mail)
        {
            StringBuilder stringBuilder = new StringBuilder();

            AE.Net.Mail.MailMessage mailMessage = new AE.Net.Mail.MailMessage();

            AE.Net.Mail.Attachment asdf = new AE.Net.Mail.Attachment();

            //MailTemplate pull

            CompositeIterator iterator     = (CompositeIterator)mail.CreateIterator();
            MailTemplate      mailTemplate = (MailTemplate)iterator.First();


            //AttachmentBox pull
            iterator = (CompositeIterator)mailTemplate.CreateIterator();
            Attachments attachmentBox = (Attachments)iterator.First();

            //Attachments pull

            iterator = (CompositeIterator)attachmentBox.CreateIterator();

            while (!iterator.IsDone())
            {
                models.components.Attachment attachment = (models.components.Attachment)iterator.CurrentItem();
                mailMessage.Attachments.Add(new AE.Net.Mail.Attachment
                {
                    Body = attachment.GetFileDirectory()
                });
            }


            mailMessage.To.Add(new MailAddress(mail.TargetMail));
            mailMessage.Subject = mailTemplate.Subject;
            mailMessage.Body    = mailTemplate.Body;
            var msgStr = new StringWriter();

            mailMessage.Save(msgStr);


            mail.FormatedMail = msgStr.ToString();
        }
示例#3
0
        public string sendMessage(string emailAdress, string destEmail, string subject, string body, List <string> attachments)
        {
            try
            {
                var msg = new AE.Net.Mail.MailMessage
                {
                    Subject = subject,
                    Body    = body,
                    From    = new MailAddress(emailAdress)
                };

                foreach (string path in attachments)
                {
                    byte[] bytes = File.ReadAllBytes(path);
                    AE.Net.Mail.Attachment file = new AE.Net.Mail.Attachment(bytes, GetMimeType(path), Path.GetFileName(path), true);
                    msg.Attachments.Add(file);
                }

                msg.To.Add(new MailAddress(destEmail));
                msg.ReplyTo.Add(msg.From); // Bounces without this!!
                var msgStr = new StringWriter();
                msg.Save(msgStr);

                var result = service.Users.Messages.Send(new Message
                {
                    Raw = Base64UrlEncode(msgStr.ToString())
                }, "me").Execute();
                Console.WriteLine("{0} : Message sent to {1}.", DateTime.Now, destEmail);
                return(DateTime.Now + " : Message sent to : " + destEmail + ".");
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return("An error occurred: " + e.Message);
            }
        }