本文整理汇总了C#中System.Net.Mail.SmtpClient.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Mail.SmtpClient.SendAsync方法的具体用法?C# System.Net.Mail.SmtpClient.SendAsync怎么用?C# System.Net.Mail.SmtpClient.SendAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.SmtpClient
的用法示例。
在下文中一共展示了System.Net.Mail.SmtpClient.SendAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: output
public override string output(System.Collections.ArrayList columnHeaders,
System.Collections.ArrayList rows,
System.Collections.Hashtable rowLengthLookup)
{
//email://[email protected]/Trial Signup Report
Regex regex = new Regex(
"(?<Proto>[a-zA-Z]*)://(?<ToAddress>[[email protected]_-]*)/(?<Subject"+
">[\\[email protected]_-]*)",
RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
if (regex.IsMatch(PropertyBag.GetProperty("data.output")))
{
Match match = regex.Match(PropertyBag.GetProperty("data.output"));
string emailAddress = match.Groups[2].Value;
string subject = match.Groups[3].Value;
Console.WriteLine("Sending email to: " + emailAddress);
string bodySrc = "";
if (PropertyBag.GetProperty("data.html", "false").ToLower() == "true")
{
OutputMethod_HTML output = new OutputMethod_HTML();
bodySrc = output.output(columnHeaders, rows, rowLengthLookup);
}
else {
OutputMethod_TXTOnly output = new OutputMethod_TXTOnly();
bodySrc = output.output(columnHeaders, rows, rowLengthLookup);
}
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
PropertyBag.GetProperty("mail.fromaddress", "[email protected]"),
emailAddress,
subject,
bodySrc);
if (PropertyBag.GetProperty("data.html", "false").ToLower() == "true")
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(
PropertyBag.GetProperty("mail.smtpserver", "127.0.0.1"), 25);
client.SendCompleted += (a, b) =>
{
Console.WriteLine("[ERROR] Failed to send email.");
};
client.SendAsync(message, message);
}
return "";
}
示例2: SendEmail
public string SendEmail()
{
string result = "";
try
{
System.Net.Mail.MailMessage mail = CreateMail();
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(host);
smtp.Port = port;
smtp.Timeout = 9999;
smtp.Credentials = new System.Net.NetworkCredential(from, password);
smtp.SendAsync(mail, null);
smtp.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(smtp_SendCompleted);
result = "ok";
}
catch (Exception ex)
{
result = ex.Message.ToString();
}
return result;
}