在我的 Web 项目中,我试图以编程方式将项目中存在的文本文件的内容发送到默认电子邮件地址。在 C# 中是否有任何简单的方法可以做到这一点?
请您参考如下方法:
类似于:
// Read the file
string body = File.ReadAllText(@"C:\\MyPath\\file.txt");
MailMessage mail = new MailMessage("you@you.com", "them@them.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "file";
// Set the read file as the body of the message
mail.Body = body;
// Send the email
client.Send(mail);
