Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
Created May 23, 2012 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichiroku11/2773028 to your computer and use it in GitHub Desktop.
Save ichiroku11/2773028 to your computer and use it in GitHub Desktop.
System.Net.Mail.SmtpClientのサンプル
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace ConsoleApp {
static class Program {
static void Main( string[] args ) {
// SMTPクライアントを作成
var client = new SmtpClient {
Host = "example.com", // SMTPサーバ
Credentials = new NetworkCredential { // 認証情報
UserName = "ユーザ名",
Password = "秘密",
},
};
// メッセージを生成して送信
using( var message = new MailMessage {} ) {
message.From = new MailAddress( "from@example.com" ); // 差出人
message.To.Add( new MailAddress( "to@example.com" ) ); // 宛先
message.Subject = "件名";
message.Body = "本文";
client.Send( message );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment