Created
February 15, 2015 12:38
-
-
Save KentaYamada/63bdd80ccd57a31fdfad to your computer and use it in GitHub Desktop.
エラーログを送信する
This file contains hidden or 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.Net; | |
using System.Net.Mail; | |
using System.Diagnostics; | |
using System.Text; | |
public static class SendErrorLog | |
{ | |
public static void Send(Exception ex) | |
{ | |
string fromAddress = "from address here"; | |
string toAddress = "to address here"; | |
string title = "mail title here"; | |
var sb = new StringBuilder(); | |
sb.AppendFormat("発生時刻:{0}\n", DateTime.Now.ToString("yyyy/MM/dd hh:mm")); | |
sb.AppendFormat("発生箇所:{0}\n", ex.TargetSite); | |
sb.AppendFormat("内容:{0}\n", ex.Message); | |
sb.AppendFormat("スタックトレース:{0}\n", ex.StackTrace); | |
using (var smtp = new SmtpClient()) | |
{ | |
smtp.Host = "host name here"; | |
smtp.Port = 999; //port no here | |
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; | |
smtp.Credentials = new NetworkCredential("username here", "password here"); //認証設定 | |
smtp.EnableSsl = true; | |
try | |
{ | |
smtp.Send(address, address, title, sb.ToString()); | |
Debug.Print("Success."); | |
} | |
catch | |
{ | |
Debug.Print("Mail send failure."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment