Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MailMessage mailMsg = new MailMessage();
- SmtpClient smtpClient = new SmtpClient();
- mailMsg.To.Add("receiver@email.com");
- mailMsg.Subject = "Application Exception";
- MemoryStream MS = new MemoryStream();
- StreamWriter Writer = new StreamWriter(MS);
- Writer.Write(DateTime.Now.ToString() + "hello");
- Writer.Flush();
- Writer.Dispose();
- // Create attachment
- ContentType ct = new ContentType(MediaTypeNames.Text.Plain);
- Attachment attach =new Attachment(MS, ct);
- attach.ContentDisposition.FileName = "Exception Log.txt";
- // Add the attachment
- mailMsg.Attachments.Add(attach);
- // Send Mail via SmtpClient
- mailMsg.Body = "An Exception Has Occured In Your Application- n";
- mailMsg.IsBodyHtml = true;
- mailMsg.From = new MailAddress("sender@email.com");
- smtpClient.Credentials = new NetworkCredential("sender@email.com", "password");
- smtpClient.Host = "smtp.gmail.com";
- smtpClient.Port = 587;
- smtpClient.EnableSsl = true;
- smtpClient.Send(mailMsg);
Add Comment
Please, Sign In to add comment