コード例 #1
0
        public static void SendFutureEventsPerShopper(string email, string firstname, string lastname, string login, List <AuctionShort> auctions, bool ishtml)
        {
            try
            {
                if (ishtml)
                {
                    UniMail.Template template = new UniMail.Template(HttpContext.Current.Server.MapPath(@"~\Templates\Mail\ReceivePersonalShopperUpdate.txt"));
                    template.Encoding = System.Text.Encoding.UTF8;
                    template.ToEmail  = email;

                    StringBuilder sb = new StringBuilder();
                    string        str, image_path;
                    str = image_path = String.Empty;
                    bool           line = true;
                    LinkedResource lr;
                    int            imgNumber = 0;
                    FileInfo       fi;

                    //fi = new FileInfo(HttpContext.Current.Server.MapPath(String.Format(@"~/public/images/logo_1.jpg")));
                    //if (fi.Exists)
                    //{
                    //  lr = new LinkedResource(fi.FullName);
                    //  lr.ContentId = "logo";
                    //  lr.TransferEncoding = TransferEncoding.Base64;
                    //  template.LinkedResourceCollection.Add(lr);
                    //}
                    //fi = new FileInfo(HttpContext.Current.Server.MapPath(String.Format(@"~/public/images/logo_text_tr.gif")));
                    //if (fi.Exists)
                    //{
                    //  lr = new LinkedResource(fi.FullName);
                    //  lr.ContentId = "logo_text";
                    //  lr.TransferEncoding = TransferEncoding.Base64;
                    //  template.LinkedResourceCollection.Add(lr);
                    //}

                    foreach (AuctionShort a in auctions)
                    {
                        image_path = a.ThumbnailPath;
                        str        = String.Empty;
                        if (!String.IsNullOrEmpty(image_path))
                        {
                            fi = new FileInfo(HttpContext.Current.Server.MapPath(AppHelper.AuctionImage(a.LinkParams.ID, image_path)));
                            if (fi.Exists)
                            {
                                lr                  = new LinkedResource(fi.FullName);
                                lr.ContentId        = "img" + (++imgNumber).ToString();
                                lr.TransferEncoding = TransferEncoding.Base64;
                                template.LinkedResourceCollection.Add(lr);
                                str = "<img src=\"cid:img" + imgNumber.ToString() + "\">";
                            }
                            else
                            {
                                str = "&nbsp;";
                            }
                        }
                        sb.AppendFormat("<tr {0}><td colspan=\"2\"><hr /></td></tr>", (line) ? "style='background-color:#d9e9f0'" : String.Empty);
                        sb.AppendFormat("<tr {0}><td align=\"left\" rowspan=\"3\" style='padding:5px'>{3}</td><td style='text-align:left;'><a href=\"{4}\"><b>{1}</b></a></td></tr><tr {0}><td>{2}</td></tr><tr {0}><td><i>{5}</i></td></tr>", (line) ? "style='background-color:#d9e9f0'" : String.Empty, a.LinkParams.Title, /*a.DescriptionWithoutTagsShort*/ String.Empty, str, AppHelper.GetSiteUrl(String.Format("/Auction/AuctionDetail/{0}/{1}/{2}/{3}", a.LinkParams.ID, a.LinkParams.EventUrl, a.LinkParams.CategoryUrl, a.LinkParams.LotTitleUrl)), String.Format("({0} ET to {1} ET)", a.StartDate, a.EndDate));
                        line = !line;
                    }

                    template.Data.Add("{{info}}", sb.ToString());
                    template.Data.Add("{{firstname}}", firstname);
                    template.Data.Add("{{lastname}}", lastname);
                    template.Data.Add("{{login}}", login);

                    ParseCommonData(template);

                    UniMail.Mailer.Enqueue(template.RenderHTML());
                }
                else
                {
                    UniMail.Template template = new UniMail.Template(HttpContext.Current.Server.MapPath(@"~\Templates\Mail\ReceivePersonalShopperUpdateText.txt"));

                    template.Encoding = System.Text.Encoding.UTF8;
                    template.ToEmail  = email;

                    StringBuilder sb = new StringBuilder();

                    foreach (AuctionShort a in auctions)
                    {
                        sb.AppendLine("Lot/Title: " + a.LinkParams.Lot + " - " + a.LinkParams.Title);
                        sb.AppendLine("" + String.Format("({0} ET to {1} ET)", a.StartDate, a.EndDate));
                        sb.AppendLine(AppHelper.GetSiteUrl(String.Format("/Auction/AuctionDetail/{0}/{1}/{2}/{3}", a.LinkParams.ID, a.LinkParams.EventUrl, a.LinkParams.CategoryUrl, a.LinkParams.LotTitleUrl)));
                        sb.AppendLine();
                    }

                    template.Data.Add("{{info}}", sb.ToString());
                    template.Data.Add("{{firstname}}", firstname);
                    template.Data.Add("{{lastname}}", lastname);
                    template.Data.Add("{{login}}", login);

                    ParseCommonData(template);
                    UniMail.Mailer.Enqueue(template.Render());
                }
            }
            catch (Exception ex)
            {
                Vauction.Utils.Lib.Logger.LogInfo("SendFutureEventsPerShopper error: " + ex.Message);
            }
        }