當前位置: 首頁>>代碼示例>>C#>>正文


C# Email.SendAsync方法代碼示例

本文整理匯總了C#中Postal.Email.SendAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# Email.SendAsync方法的具體用法?C# Email.SendAsync怎麽用?C# Email.SendAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Postal.Email的用法示例。


在下文中一共展示了Email.SendAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Contact

        public async Task<ActionResult> Contact(Models.ContactViewModel contact)
        {
            if (ModelState.IsValid)
            {
                var currentTime = DateTime.UtcNow;
                var elapsedTime = currentTime - contact.TimeSent;
                bool spamFieldFull = !string.IsNullOrEmpty(contact.Check);

                dynamic email = new Email("ContactForm");
                email.From = contact.Email;
                email.CurrentTime = currentTime;
                email.Name = contact.Name;
                email.Title = contact.Title;
                email.Phone = contact.Phone;
                email.Company = contact.Company;
                email.Address = contact.Address;
                email.City = contact.City;
                email.State = contact.State;
                email.Zip = contact.Zip;
                email.Country = contact.Country;
                email.Comments = contact.Comments;
                email.Elapsed = elapsedTime;
                email.SpamFieldFull = spamFieldFull;

                await email.SendAsync();
                return RedirectToAction("ContactSuccess");                                
            }

            return View(contact);
        }
開發者ID:sjpence,項目名稱:unitdesign-web,代碼行數:30,代碼來源:HomeController.cs

示例2: Execute

 public void Execute(ErrorLog errorLog)
 {
     if(string.IsNullOrWhiteSpace(Settings.To)) return;
     dynamic email = new Email("ErrorLog");
     email.From = Settings.From ?? "[email protected]" + errorLog.Host;
     email.To = Settings.To;
     email.Subject = string.Format(Settings.SubjectFormat ?? "Error ({0}): {1}", errorLog.Type, errorLog.Message).Replace(@"\r\n", " ");
     email.Time = errorLog.Time;
     email.Detail = errorLog.Detail;
     email.ServerVariables = errorLog.ServerVariables;
     if(Settings.AttachOriginalError && !string.IsNullOrWhiteSpace(errorLog.Html))
         email.Attach(Attachment.CreateAttachmentFromString(errorLog.Html, "Original ASP.NET error page.html", Encoding.UTF8, "text/html"));
     email.SendAsync();
 }
開發者ID:stevenbey,項目名稱:elfar,代碼行數:14,代碼來源:ErrorLogPlugin.cs

示例3: Send

        public ActionResult Send(string @from, string to, string subject, string message, HttpPostedFileBase file)
        {
            //Regular sending
              //  Helpers.Email.SendEmail(@from,to, "http://localhost:56224/Emails/SendToFriend/SendToFriend.aspx");

            //System.Net.Mail.Attachment attachment;
            //attachment = new System.Net.Mail.Attachment("your attachment file");
            //email.Attachments.Add(attachment);

            // This will look for a view in "~/Views/Emails/Example.cshtml".
            dynamic email = new Email("SendtoFriend/Multipart");
            // Assign any view data to pass to the view.
            // It's dynamic, so you can put whatever you want here.
            email.To = to;
            email.From = @from;
            email.Title = "Custom Title";
            email.Subject = subject;
            email.Message = message;
            email.Date = DateTime.UtcNow;
            ViewBag.Poster = "[email protected]";

            if (file != null)
            {
                email.Attach(new Attachment(file.InputStream, file.FileName));
            }

            // Send the email via a default Postal.EmailService object.
            // This will use the web.config smtp settings.
            try
            {
                email.SendAsync();

            }
            catch (Exception)
            {
                //Write To Database Error
                //Output Message
                Response.Write("Fail");
                throw;
            }

            return RedirectToAction("Sent");
        }
開發者ID:haithemaraissia,項目名稱:RentalMVCClean,代碼行數:43,代碼來源:EmailTestController.cs


注:本文中的Postal.Email.SendAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。