private SendMailAsync ( |
||
message | ||
return | System.Threading.Tasks.Task |
using System.Net.Mail; // Create a new MailMessage object MailMessage message = new MailMessage("[email protected]", "[email protected]"); // Set the subject and body of the email message.Subject = "Hello, World!"; message.Body = "This is a test email message."; // Create a new SmtpClient object and set its properties SmtpClient client = new SmtpClient("smtp.gmail.com"); client.Port = 587; client.Credentials = new NetworkCredential("[email protected]", "password"); client.EnableSsl = true; // Send the email asynchronously await client.SendMailAsync(message);
using System.Net.Mail; // Create a new MailMessage object MailMessage message = new MailMessage("[email protected]", "[email protected]"); // Set the subject and body of the email message.Subject = "Hello, World!"; message.Body = "This is a test email message with an attachment."; // Create a new attachment object and add it to the email message Attachment attachment = new Attachment("C:/path/to/file.txt"); message.Attachments.Add(attachment); // Create a new SmtpClient object and set its properties SmtpClient client = new SmtpClient("smtp.gmail.com"); client.Port = 587; client.Credentials = new NetworkCredential("[email protected]", "password"); client.EnableSsl = true; // Send the email asynchronously await client.SendMailAsync(message);In this example, we create a new MailMessage object with the sender and recipient email addresses, set the subject and body of the email, create a new Attachment object with the file path, add the attachment to the email message, create a new SmtpClient object with the necessary properties, and send the email asynchronously using the SendMailAsync method. The System.Net.Mail namespace is part of the .NET Framework Class Library, which is included with the .NET Framework.
private SendMailAsync ( |
||
message | ||
return | System.Threading.Tasks.Task |