プログラムのクリックボタン機能でコンソール出力を電子メールで送信する方法についてサポートが必要です。
変数に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は、MailKitおよびMimeKitライブラリを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", "[email protected]"));
message.To.Add (new MailboxAddress ("Receiver's Name", "[email protected]"));
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);
}
}
}
}
詳しくは:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加