using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MailKit.Security; namespace Ymobile2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { /* MailMessage msg = new MailMessage(); msg.From = new MailAddress("seedagx16@yahoo.ne.jp", "Yoshikazu Yamamoto"); msg.To.Add(new MailAddress("seedagx16@yahoo.ne.jp", "Yoshikazu Yamamoto")); msg.Subject = "test"; msg.Body = "This is a test message."; SmtpClient sc = new SmtpClient(); sc.Host = "ymobilesmtp.mail.yahoo.ne.jp"; sc.Port = 465; sc.DeliveryMethod = SmtpDeliveryMethod.Network; sc.Credentials = new System.Net.NetworkCredential("seedagx16@yahoo.ne.jp", "Bzc2xgc7Iwada"); sc.EnableSsl = true; sc.Send(msg); msg.Dispose(); textBox1.Text += "メールを送信しました\r\n"; */ string host = "ホスト名"; int port = 465; try { using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { //第3引数のオプションでTLS(SSL)を使うかどうか指定する smtp.Connect(host, port, SecureSocketOptions.SslOnConnect); smtp.Authenticate("ユーザー名", "パスワード"); var mail = new MimeKit.MimeMessage(); var builder = new MimeKit.BodyBuilder(); mail.From.Add(new MimeKit.MailboxAddress("", "送信者アドレス")); mail.To.Add(new MimeKit.MailboxAddress("", "受信者アドレス")); mail.Subject = "題名:テスト"; builder.TextBody = "テストです。"; mail.Body = builder.ToMessageBody(); smtp.Send(mail); smtp.Disconnect(true); textBox1.Text += "メールを送信しました。\r\n"; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }