Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.Hosting;
- using System.Net;
- using System.Net.Mail;
- using System.Configuration;
- using System.IO;
- using System.Collections;
- //using System.Web.HttpContext.Current.Server;
- public class htmlsend
- {
- //public static string details;
- //static void Main(string[] args)
- static void Main()
- {
- string body = string.Empty;
- //using (StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage1.html")))
- //using (StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/mappathtest.html")))
- //using (StreamReader reader = new StreamReader(HostingEnvironment.MapPath("~/mappathtest.html")))
- using (StreamReader reader = new StreamReader(("mappathtest.html")))
- {
- body = reader.ReadToEnd();
- string userName = "jack";
- string title = "titlestring";
- string url = "urlstring";
- string description = "descriptionstring";
- body = body.Replace("{UserName}", userName);
- body = body.Replace("{Title}", title);
- body = body.Replace("{Url}", url);
- body = body.Replace("{Description}", description);
- //return body;
- //bodystring(body);
- email(body);
- }
- }
- /*public static void bodystring(string body)
- {
- Console.WriteLine(body);
- }*/
- public static void email(string body)
- {
- {
- string myemailaddress = "";
- var fromAddress = new MailAddress(myemailaddress, "");
- var toAddress = new MailAddress("", "");
- const string fromPassword = "";
- const string subject = "Subject";
- //string body = globalList.ToString();
- string htmlbody = body;
- /*for (int i = 0; i < globalList.Count; i++)
- {
- body = body + globalList[i].ToString();
- Console.WriteLine(globalList[i].ToString());
- }*/
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- using (var message = new MailMessage(fromAddress, toAddress)
- {
- Subject = subject,
- Body = htmlbody
- })
- {
- smtp.Send(message);
- Console.WriteLine("emailsent");
- }
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement