Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void WelcomeMail(string recipient)
- {
- MailMessage mailMessage = new MailMessage("MyEmail", recipient);
- StringBuilder sbEmailBody = new StringBuilder();
- sbEmailBody.Append("How can I attach .html file here instead of writing the whole code");
- mailMessage.IsBodyHtml = true;
- mailMessage.Body = sbEmailBody.ToString();
- mailMessage.Subject = "Welcome to domain.com";
- SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
- smtpClient.Credentials = new System.Net.NetworkCredential()
- {
- UserName = "MyEmail",
- Password = "MyPassword"
- };
- smtpClient.EnableSsl = true;
- smtpClient.Send(mailMessage);
- }
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <body style="font-family: 'Open Sans', sans-serif;">
- <div style="padding: 30px 30px 20px 30px;">
- <div style="padding: 30px 20px; background: #fff; font-size: 14px; color: #555; border-radius: 4px;">
- <p class="greeting" style="margin: 0;">Hello {UserName},</p>
- <p class="message" style="margin: 20px 0;">
- {Message}
- </p>
- </div>
- </div>
- </body>
- </html>
- string body = string.Empty;
- string UserName = string.Empty;
- string message = "This is a test email.";
- StreamReader Reader = null;
- WebRequest WebRequest = null;
- WebResponse WebResponse = null;
- WebRequest = WebRequest.Create("your_html_template_filePath");
- WebRequest.Timeout = 30 * 60 * 1000;
- WebRequest.UseDefaultCredentials = true;
- WebResponse = _WebRequest.GetResponse();
- Reader = new StreamReader(WebResponse.GetResponseStream());
- body = _Reader.ReadToEnd;
- body = body.Replace("{UserName}", UserName);
- body = body.Replace("{Message}", message);
- Reader.Close();
- if (_Reader != null)
- {
- _Reader.Dispose();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement