本文整理汇总了C#中System.Net.Mail.MailMessage.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.SendAsync方法的具体用法?C# MailMessage.SendAsync怎么用?C# MailMessage.SendAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了MailMessage.SendAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QuickMail
/// <summary>
/// When task is started mail will be sent asynchronously
/// </summary>
/// <param name="body"></param>
/// <param name="sub"></param>
/// <param name="to"></param>
/// <param name="isHtml"></param>
/// <param name="send"></param>
/// <param name="NotifyDeveloper"></param>
/// <param name="NotifyAdmin"></param>
/// <returns></returns>
public Task QuickMail(string body, string sub, string to = "", bool isHtml = true, bool send = true, bool NotifyDeveloper = false, bool NotifyAdmin = false)
{
Task t = new Task(() => {
var mail = new MailMessage();
mail.Subject = sub;
mail.Body = body;
mail.IsBodyHtml = isHtml;
if (send) {
if (to != "" && to != null) {
mail.To.Add(to);
}
if (NotifyAdmin && Config.AdminEmail != null) {
mail.To.Add(Config.AdminEmail);
}
if (NotifyDeveloper && Config.DeveloperEmail != null) {
mail.To.Add(Config.DeveloperEmail);
}
}
mail.SendAsync();
});
if (send) {
t.Start();
}
return t;
}
示例2: SendAsync
public void SendAsync()
{
var token = new object();
// Type
var @this = new MailMessage("[email protected]", "[email protected]", "Fizz", "Buzz");
// Examples
@this.SendAsync(token); // Send a mail async
}
示例3: should_send_async_and_call_back
public void should_send_async_and_call_back()
{
var message = new MailMessage("[email protected]", "[email protected]", "subject", "body");
var wait = new ManualResetEvent(false);
message.SendAsync((x,client)=>
{
Assert.AreEqual("test1State", x);
Trace.WriteLine(x);
wait.Set();
} , "test1State");
var result = wait.WaitOne(TimeSpan.FromSeconds(2));
Assert.IsTrue(result);
}
示例4: Send
/// <summary>
/// Calls SetMailDefaults first.
/// </summary>
/// <param name="mail"></param>
/// <param name="subject"></param>
/// <param name="to"></param>
public void Send(MailMessage mail, string subject = "", string to = "")
{
mail = SetMailDefaults(mail);
if (subject != null && subject == "") {
mail.Subject = subject;
}
if (to != null && to != "") {
mail.To.Add(to);
}
try {
new Thread(() => {
if (SEND_ASY)
mail.SendAsync();
else
mail.Send();
}).Start();
} catch (Exception) {
}
}
示例5: should_send_async
public void should_send_async()
{
var message = new MailMessage("[email protected]", "[email protected]", "subject", "body");
message.SendAsync();
}