本文整理汇总了C#中Postal.Email.Attach方法的典型用法代码示例。如果您正苦于以下问题:C# Email.Attach方法的具体用法?C# Email.Attach怎么用?C# Email.Attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Postal.Email
的用法示例。
在下文中一共展示了Email.Attach方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendReportMail
public static void SendReportMail(List<string> attachmentPaths, ContractUser user)
{
dynamic email = new Email("ReportMail");
email.to = user.Email;
email.from = applicationEmail;
foreach(string path in attachmentPaths)
{
email.Attach(new Attachment(path));
}
email.Send();
}
示例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();
}
示例3: Attachments_are_added_to_MailMessage
public void Attachments_are_added_to_MailMessage()
{
var input = @"
To: [email protected]
From: [email protected]
Subject: Test Subject
Hello, World!";
var email = new Email("Test");
email.Attach(new Attachment(new MemoryStream(), "name"));
var parser = new EmailParser(Mock.Of<IEmailViewRenderer>());
var message = parser.Parse(input, email);
message.Attachments.Count.ShouldEqual(1);
}
示例4: 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");
}
示例5: Send
public ActionResult Send(string to, string subject, string message, HttpPostedFileBase file)
{
// This will look for a view in "~/Views/Emails/Example.cshtml".
dynamic email = new Email("Example");
// Assign any view data to pass to the view.
// It's dynamic, so you can put whatever you want here.
email.To = to;
email.Subject = subject;
email.Message = message;
email.Date = DateTime.UtcNow;
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.
email.Send();
// In 'real code' you probably want to use the Postal.IEmailService interface
// to allow for mocking out the sending of email in tests.
//
// The controller's constructor would look like this:
// public HomeController(IEmailService emailService) {
// this.emailService = emailService;
// }
//
// Then actions can send email using:
// emailService.Send(email);
// Alternatively, you can just ask for the MailMessage to be created.
// It contains the rendered email body and headers (To, From, etc).
// You can then send this yourself using any method you like.
// using (var mailMessage = emailService.CreateMailMessage(email))
// {
// MyEmailGateway.Send(mailMessage);
// }
return RedirectToAction("Sent");
}
示例6: Email
public JsonResult Email(string email, string path)
{
string root = ConfigurationManager.AppSettings["FilesRoot"];
root = root.Trim().EndsWith(@"\") ? root = root.Substring(0, root.Length - 2) : root;
var fullpath = string.Format(@"{0}{1}", ConfigurationManager.AppSettings["FilesRoot"], path.Replace("/", "\\"));
var cookie = Request.Cookies["rephidim"];
if (cookie == null)
{
cookie = new HttpCookie("rephidim");
}
cookie["email"] = email;
cookie.Expires = DateTime.Now.AddMonths(12);
Response.Cookies.Add(cookie);
dynamic msg = new Email("FileAttach");
msg.To = email;
msg.Path = path;
msg.Attach(new System.Net.Mail.Attachment(fullpath));
msg.Send();
return Json(true);
}
示例7: Attach_adds_attachment
public void Attach_adds_attachment()
{
dynamic email = new Email("Test");
var attachment = new Attachment(new MemoryStream(), "name");
email.Attach(attachment);
((Email)email).Attachments.ShouldContain(attachment);
}