-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cs
40 lines (35 loc) · 1.13 KB
/
a.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Net;
using System.Net.Mail;
class Program
{
static void Main(string[] args)
{
try
{
// Configure SMTP client
var smtpClient = new SmtpClient("smtp.example.com")
{
Port = 587, // Common SMTP port
Credentials = new NetworkCredential("your-email@example.com", "your-password"),
EnableSsl = true, // Secure connection
};
// Create the email
var mailMessage = new MailMessage
{
From = new MailAddress("your-email@example.com"),
Subject = "Hello from .NET",
Body = "This is a test email sent using .NET.",
IsBodyHtml = false, // Set to true if you want to send HTML email
};
mailMessage.To.Add("recipient@example.com");
// Send the email
smtpClient.Send(mailMessage);
Console.WriteLine("Email sent successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to send email: {ex.Message}");
}
}
}