如何将控制台输出发送到我的电子邮件?



我想获得有关如何通过电子邮件通过程序中单击按钮功能发送控制台输出的帮助。

变量textBox2.Text包含正在打印到控制台的文本,我希望此文本在 (button1_Click_1( 函数上自动发送。

我已经在有些类似的问题上找到了一些解决方案,但它们似乎都不起作用,我希望我能在这里找到解决方案。

我的代码:

private void textBox2_TextChanged(object sender, EventArgs e)
{
Console.WriteLine(textBox2);
}
private void button1_Click_1(object sender, EventArgs e)
{
//Sending email function with the console output that is being printed from (textBox2.Text) should be here.
Taskbar.Show();
System.Windows.Forms.Application.Exit();
}

Microsoft建议使用MailKitMimeKit库从 C# 应用程序发送电子邮件。

以下是 C# 中用于发送电子邮件的工作代码片段:

// File name:  SendMail.cs
using System;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
namespace SendMail {
class Program
{
public static void Main (string[] args) {
using (var client = new SmtpClient ()) {
// Connect to the email service (Accept ssl certificate)
client.ServerCertificateValidationCallback = (s,c,h,e) => true;
client.Connect ("smtp.friends.com", 587, false);

// Optional step: Send user id, password, if the server requires authentication
client.Authenticate ("emailID", "emailPassword");

// Construct the email message
var message = new MimeMessage();
message.From.Add (new MailboxAddress ("Sender's Name", "sender-email@example.com"));
message.To.Add (new MailboxAddress ("Receiver's Name", "receiver-email@example.com"));
message.Subject = "Automatic email from the application";
message.Body = new TextPart ("plain") { Text = @"Hello Customer, Happy new year!"};

// Send the email
client.Send (message);

// Close the connection with the email server
client.Disconnect (true);
}
}
}
}

更多信息:

https://github.com/jstedfast/MailKit

相关内容

最新更新