Created
May 23, 2012 03:04
-
-
Save ichiroku11/2773028 to your computer and use it in GitHub Desktop.
System.Net.Mail.SmtpClientのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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