コード例 #1
0
        /// <summary>
        /// Send MAIL
        /// </summary>
        /// <param name="recipientAddress"></param>
        /// <param name="recipientName"></param>
        /// <param name="senderAddress"></param>
        /// <param name="actionName"></param>
        /// <param name="mailType"></param>
        /// <param name="lang"></param>
        /// <param name="dataToReplace"></param>
        public OperationResult <bool> Send(string recipientAddress, string recipientName, string senderAddress, string actionName,
                                           MailTypes mailType, Langs.LangsEnum lang, Dictionary <string, string> dataToReplace)
        {
            try {
                var body = GetEmailBody(mailType);

                var from    = new MailAddress(senderAddress, Resources.Email.Connection.FromName);
                var to      = new MailAddress(recipientAddress, recipientName);
                var message = new MailMessage(from, to)
                {
                    Subject    = actionName,
                    Body       = body,
                    IsBodyHtml = true
                };

                body    = FullFillBodyContent(body, lang, dataToReplace);
                message = AddImagesToBody(message, body, mailType);

                // Send msg
                _smtpClient.SendMailAsync(message);
                return(new OperationResult <bool>());
            }
            catch (Exception ex) {
                return(new OperationResult <bool>(ex));
            }
        }
コード例 #2
0
        private string GetEmailBody(MailTypes mailType)
        {
            string body;

            switch (mailType)
            {
            case MailTypes.Confirm: { body = Resources.Email.Bodies.EmailConfirm; break; }

            case MailTypes.Deactivation: { body = Resources.Email.Bodies.EmailDeactAccount; break; }

            case MailTypes.Delete: { body = Resources.Email.Bodies.EmailDeleteAccount; break; }

            case MailTypes.NewTask: { body = Resources.Email.Bodies.EmailNewTask; break; }

            case MailTypes.News: { body = Resources.Email.Bodies.EmailNews; break; }

            case MailTypes.PasswordRecovery: { body = Resources.Email.Bodies.EmailPasswordRecovery; break; }

            case MailTypes.TaskResponse: { body = Resources.Email.Bodies.EmailTaskResponse; break; }

            case MailTypes.Warning: { body = Resources.Email.Bodies.EmailWarning; break; }

            default: throw new ArgumentOutOfRangeException(nameof(mailType), mailType, null);
            }
            return(body);
        }
コード例 #3
0
        public static async void SearchMails()
        {
            List <string> Urls       = new List <string>();
            string        city       = Cities.GetRandomCity();
            string        profession = Professions.GetRandomProfession();
            string        mailType   = MailTypes.GetRandomMailType();

            string q = "דרוש/ה " + profession + " ב" + city + " " + mailType;

            q = q.Replace(" ", "+");

            for (int i = 10; i > 1; i--)
            {
                string        query = string.Format("http://search.walla.co.il/?q={0}&type=text&page={1}", q, i);
                string        g     = getPageSource(query);
                List <string> urls  = GetUrls(g);
                foreach (string u in urls)
                {
                    Urls.Add(u);
                }
            }

            foreach (string u in Urls)
            {
                if (!string.IsNullOrEmpty(u))
                {
                    GetMails(u);
                }
            }
        }
コード例 #4
0
        private Dictionary <string, byte[]> GetImagesBodies(MailTypes mailType)
        {
            var result = new Dictionary <string, byte[]>();

            // {{ GetNameOf(() => Resources.Email.Image.ImgFacebook), Convert.FromBase64String(Resources.Email.Image.ImgFacebook)},
            // { GetNameOf(() => Resources.Email.Image.ImgVK), Convert.FromBase64String(Resources.Email.Image.ImgVK)},
            // { GetNameOf(() => Resources.Email.Image.ImgTwitter), Convert.FromBase64String(Resources.Email.Image.ImgTwitter)},
            // { GetNameOf(() => Resources.Email.Image.ImgGoogle), Convert.FromBase64String(Resources.Email.Image.ImgGoogle)},
            // { GetNameOf(() => Resources.Email.Image.ImgLinkedin), Convert.FromBase64String(Resources.Email.Image.ImgLinkedin)},
            // { GetNameOf(() => Resources.Email.Image.ImgInstagram), Convert.FromBase64String(Resources.Email.Image.ImgInstagram)}};

            switch (mailType)
            {
            case MailTypes.Confirm: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoBlue), Convert.FromBase64String(Resources.Email.Image.ImgLogoBlue));
                //result.Add(GetNameOf(() => Resources.Email.Image.ImgProfit), Convert.FromBase64String(Resources.Email.Image.ImgProfit));
                break;
            }

            case MailTypes.Deactivation: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoPink), Convert.FromBase64String(Resources.Email.Image.ImgLogoPink));
                break;
            }

            case MailTypes.Delete: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoDark), Convert.FromBase64String(Resources.Email.Image.ImgLogoDark));
                break;
            }

            case MailTypes.NewTask: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoLGreen), Convert.FromBase64String(Resources.Email.Image.ImgLogoLGreen));
                break;
            }

            case MailTypes.News: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoGreen), Convert.FromBase64String(Resources.Email.Image.ImgLogoGreen));
                //result.Add(GetNameOf(() => Resources.Email.Image.ImgProfit), Convert.FromBase64String(Resources.Email.Image.ImgProfit));
                break;
            }

            case MailTypes.PasswordRecovery: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoDBlue), Convert.FromBase64String(Resources.Email.Image.ImgLogoDBlue));
                break;
            }

            case MailTypes.TaskResponse: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoLGreen), Convert.FromBase64String(Resources.Email.Image.ImgLogoLGreen));
                break;
            }

            case MailTypes.Warning: {
                result.Add(GetNameOf(() => Resources.Email.Image.ImgLogoYellow), Convert.FromBase64String(Resources.Email.Image.ImgLogoYellow));
                break;
            }
            }
            return(result);
        }
コード例 #5
0
ファイル: SendMail.cs プロジェクト: ywyonui/CScan
 //构造函数,New SMTP变量实例
 public SendMail()
 {
     //初始化邮件信息
     MailMessage_my = new MailMessage();
     pFailInfo      = "";
     IsAnonymous    = 0;
     pblnSuccess    = true;
     pMailType      = MailTypes.Html;
     pMailEncoding  = MailEncodings.UTF8;
     pPriority      = EmailPriory.Normal;
 }
コード例 #6
0
ファイル: Mailer.cs プロジェクト: s-idzikowski/Shop
        public static void SendRegisterMail(this User user, MailTypes mailType, string token)
        {
            MailMessage mail = user.GetMailMessage();

            mail.Subject = "Stworzono konto w serwisie Shop!";
            mail.Body    = $"Witaj, {user.Username}";
            mail.Body   += Environment.NewLine;
            mail.Body   += "Potwierdz swoj adres email klikajac w ponizszy link:";
            mail.Body   += Environment.NewLine;
            mail.Body   += $"http://localhost:3000/verifyaccount?Bearer={token}";

            Send(mail);
        }
コード例 #7
0
        private MailMessage AddImagesToBody(MailMessage message, string body, MailTypes mailType)
        {
            var imagesBodies = GetImagesBodies(mailType);

            // Add Alternate Views
            foreach (var imageBody in imagesBodies)
            {
                var linkedResource = new LinkedResource(new MemoryStream(imageBody.Value), MediaTypeNames.Image.Jpeg)
                {
                    ContentId        = imageBody.Key,
                    TransferEncoding = TransferEncoding.Base64,
                };
                var av = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                av.LinkedResources.Add(linkedResource);
                message.AlternateViews.Add(av);
            }
            return(message);
        }
コード例 #8
0
ファイル: Mailer.cs プロジェクト: nkanish2002/Aurora
        public static void SendMail(string[] Recipients, string body, MailTypes Type)
        {
            var message = new MailMessage();
            message.IsBodyHtml = true;
            message.From = new MailAddress(username, "Support@CIR");
            message.Body = body;
            message.Subject = "No-Reply: " + Type.ToString();

            foreach (var recipient in Recipients)
            {
                message.To.Add(new MailAddress(recipient));
            }

            var mailer = new SmtpClient(host, port);
            mailer.EnableSsl = true;
            mailer.Credentials = new NetworkCredential(username, password);
            mailer.Send(message);
        }
コード例 #9
0
ファイル: Spider.ashx.cs プロジェクト: orassayag/cv-spider-v4
        /*Description:
         */
        public void SearchMails()
        {
            List <string> urls        = null;
            string        city        = Cities.GetRandomCity();
            string        profession  = Professions.GetRandomProfession();
            string        mailType    = MailTypes.GetRandomMailType();
            string        querySearch = string.Format($"דרוש/ה+{profession}+ב{city}+{mailType}");

            for (int i = 10; i > 1; i--)
            {
                string query      = string.Format("http://search.walla.co.il/?q={0}&type=text&page={1}", querySearch, i);
                string pageSource = TextUtils.GetPageSource(query);
                urls = TextUtils.GetUrls(pageSource);
            }

            foreach (string u in urls)
            {
                if (!string.IsNullOrEmpty(u))
                {
                    GetMails(u);
                }
            }
        }
コード例 #10
0
ファイル: Mailer.cs プロジェクト: nkanish2002/Aurora
        public static string LoadTemplate(MailTypes Type, Dictionary<string, string> Values)
        {
            string url = "";

            switch (Type)
            {
                case MailTypes.RegistrationRequest:
                    url = "EmailTemplates\\RegistrationRequest.html"; break;

                case MailTypes.RegistrationSuccessful:
                    url = "EmailTemplates\\RegistrationSuccessful.html"; break;

                case MailTypes.AccountConnected:
                    url = "EmailTemplates\\AccountConnected.html"; break;

                case MailTypes.RegisteredForPlacements:
                    url = "EmailTemplates\\RegisteredForPlacements.html"; break;

                case MailTypes.RequestPlacementRegistration:
                    url = "EmailTemplates\\RequestPlacementRegistration.html"; break;

                case MailTypes.Notification:
                    url = "EmailTemplates\\Notification.html"; break;

                case MailTypes.TestMail:
                    url = "EmailTemplates\\Test.html"; break;
            }

            var body = File.ReadAllText(url);
            foreach (var key in Values.Keys)
            {
                body = body.Replace("{{" + key + "}}", Values[key]);
            }

            return body;
        }
コード例 #11
0
        static private MailMessage getMailWithImg(MailAddress fromAddress, MailAddress toAddress, string subject, string filePath, Model model, MailTypes mailTypes)
        {
            string bodyAdd = "";

            switch (mailTypes)
            {
            case MailTypes.addTask:
                bodyAdd = EmailBodyToAddTask((TaskModel)model);
                break;

            case MailTypes.addMeeting:
                bodyAdd = EmailBodyToAddMeeting((MeetingModel)model);
                break;

            case MailTypes.editMeeting:
                bodyAdd = EmailBodyToEditMeeting((MeetingModel)model);
                break;

            case MailTypes.addEmployee:
                bodyAdd = EmailBodyToAddEmployee((User)model);
                break;

            case MailTypes.editTask:
                bodyAdd = EmailBodyToEditTask((TaskModel)model);
                break;
            }
            MailMessage mail = new MailMessage(fromAddress, toAddress);

            mail.IsBodyHtml = true;
            mail.AlternateViews.Add(getEmbeddedImage(filePath, bodyAdd));
            mail.Subject = subject;
            return(mail);
        }
コード例 #12
0
        public static void SendMessage(string addressTo, string addressee, string subject, Model model, MailTypes mailTypes)
        {
            MailAddress  fromAddress  = new MailAddress("*****@*****.**", "What's Today");
            MailAddress  toAddress    = new MailAddress(addressTo, addressee);
            const string fromPassword = "******";
            string       filePath     = @"Content\Image\logo_mini.png";

            var smtp = new SmtpClient
            {
                Host           = "smtp.gmail.com",
                Port           = 587,
                EnableSsl      = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout        = 20000
            };

            MailMessage mailWithImg = getMailWithImg(fromAddress, toAddress, subject, filePath, model, mailTypes);

            smtp.Send(mailWithImg);
        }