本文整理汇总了C#中System.Net.Mail.SmtpClient.SendMailAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Mail.SmtpClient.SendMailAsync方法的具体用法?C# System.Net.Mail.SmtpClient.SendMailAsync怎么用?C# System.Net.Mail.SmtpClient.SendMailAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.SmtpClient
的用法示例。
在下文中一共展示了System.Net.Mail.SmtpClient.SendMailAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAsync
public Task SendAsync(IdentityMessage message)
{
// Credentials:
var credentialUserName = ConfigurationManager.AppSettings["CredentialUserName"];
var sentFrom = ConfigurationManager.AppSettings["SentFrom"];
var pwd = ConfigurationManager.AppSettings["EmailPassword"];
// Configure the client:
System.Net.Mail.SmtpClient client =
new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
client.Port = 587;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
// Create the credentials:
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(credentialUserName, pwd);
client.EnableSsl = true;
client.Credentials = credentials;
// Create the message:
var mail =
new System.Net.Mail.MailMessage(sentFrom, message.Destination);
mail.Subject = message.Subject;
mail.Body = message.Body;
mail.IsBodyHtml = true;
// Send:
return client.SendMailAsync(mail);
}
示例2: ConfigHotmailAccount
private async Task ConfigHotmailAccount(IdentityMessage message)
{
// Credentials:
var credentialUserName = ConfigurationManager.AppSettings["emailService:Account"];
var sentFrom = credentialUserName;
var pwd = ConfigurationManager.AppSettings["emailService:Password"];
// Configure the client:
System.Net.Mail.SmtpClient client =
new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
client.Port = 587;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
// Create the credentials:
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(credentialUserName, pwd);
client.EnableSsl = true;
client.Credentials = credentials;
// Create the message:
var mail =
new System.Net.Mail.MailMessage(sentFrom, message.Destination);
mail.Subject = message.Subject;
mail.Body = message.Body;
// Send:
await client.SendMailAsync(mail);
}
示例3: SendAsync
public static Task SendAsync(string destination, string subject, string body)
{
var credentialUserName = "[email protected]";
var sentFrom = "[email protected]";
var pwd = "quiko";
// Configure the client:
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.riquest.de");
client.Port = 25;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
// Create the credentials:
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd);
client.EnableSsl = false;
client.Credentials = credentials;
// Create the message:
var mail = new System.Net.Mail.MailMessage(sentFrom, destination);
mail.Subject = subject;
mail.Body = body;
// Send:
return client.SendMailAsync(mail);
}
示例4: SendEmailAsync
public Task SendEmailAsync(string email, string subject, string message)
{
// Credentials:
var credentialUserName = "[email protected]";
var sentFrom = "[email protected]";
var pwd = "rua13demaio";
// Configure the client:
System.Net.Mail.SmtpClient client =
new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
client.Port = 587;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
// Create the credentials:
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(credentialUserName, pwd);
client.EnableSsl = true;
client.Credentials = credentials;
// Create the message:
var mail = new System.Net.Mail.MailMessage(sentFrom, email);
mail.IsBodyHtml = true;
mail.Subject = subject;
mail.Body = message;
// Send:
return client.SendMailAsync(mail);
}
示例5: SendAsync
public Task SendAsync(string destination, string subject, string body)
{
const string credentialUserName = "[email protected]";
const string sentFrom = "[email protected]";
const string pwd = "Itadakimas2014";
var client =
new System.Net.Mail.SmtpClient("smtp-mail.outlook.com")
{
Port = 587,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
UseDefaultCredentials = false
};
var credentials =
new NetworkCredential(credentialUserName, pwd);
client.EnableSsl = true;
client.Credentials = credentials;
var mail =
new System.Net.Mail.MailMessage(sentFrom, destination)
{
Subject = subject,
Body = body
};
return client.SendMailAsync(mail);
}