gpt4 book ai didi

c# - 以编程方式将文本文件的内容发送到电子邮件地址

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:36 24 4
gpt4 key购买 nike

在我的 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);

关于c# - 以编程方式将文本文件的内容发送到电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com