Beispiel #1
0
 private static MailMessage addFilesToMessage(MessageGmail originalMessage, MailMessage msg)
 {
     if (originalMessage.ListFileAttachment != null)
     {
         foreach (var file in originalMessage.ListFileAttachment)
         {
             ContentType   mimeType  = new ContentType("text/html");
             AlternateView alternate = AlternateView.CreateAlternateViewFromString(msg.Body, mimeType);
             msg.Attachments.Add(file);
             msg.AlternateViews.Add(alternate);
         }
     }
     return(msg);
 }
Beispiel #2
0
        private static MailMessage createMessage(MessageGmail message)
        {
            MailMessage msg = new MailMessage()
            {
                From            = fromAddress,
                Subject         = message.Subject,
                Body            = message.Body,
                IsBodyHtml      = message.IsBodyHtml,
                SubjectEncoding = Encoding.UTF8,
                BodyEncoding    = Encoding.UTF8
            };

            //מצרף את כתובות המייל לשליחה
            foreach (var address in message.ToList)
            {
                var ToAddress = new MailAddress(address.Value, address.Key);
                msg.To.Add(ToAddress);
            }
            return(msg);
        }
Beispiel #3
0
        public static bool SendEMail(MessageGmail message)
        {
            var success = false;
            var msg     = createMessage(message);

            msg = addFilesToMessage(message, msg);

            var client = createClient();

            try
            {
                client.Send(msg);
                success = true;
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(success);
        }