Guest User

Untitled

a guest
Nov 27th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. Simple ASP.NET mail script
  2.  
  3. <% @Page Language="C#" %>
  4. <% @Import Namespace="System.Web.Mail" %>
  5. <%
  6. string strTo = "mailhostingserver@gmail.com";
  7. string strFrom = "sender@yourdomain.com";
  8. string strSubject = "Hi User";
  9.  
  10. SmtpMail.Send(strFrom, strTo, strSubject,
  11. "A real nice body text here");
  12.  
  13. Response.Write("Email was queued to disk");
  14. %>
  15.  
  16. Note: Name the file as <filename>.aspx
  17. Some other script that worked when the above didnt!
  18.  
  19. <% @Page Language="C#" %>
  20. <% @Import Namespace="System.Net.Mail" %>
  21. <%
  22. SmtpClient client = new SmtpClient("localhost");
  23. MailAddress from = new MailAddress("testing@domainname.tld");
  24.  
  25. MailAddress to = new MailAddress("mailhostingserver@gmail.com");
  26.  
  27. MailMessage message = new MailMessage(from, to);
  28. message.Body = "Testing";
  29.  
  30. message.BodyEncoding = System.Text.Encoding.ASCII;
  31. message.Subject = "testing";
  32. message.SubjectEncoding = System.Text.Encoding.ASCII;
  33. client.Send(message);
  34. Response.Write("Email sent");
  35. %>
  36. Sending HTML Email
  37.  
  38. <% @Page Language="C#" %>
  39. <% @Import Namespace="System.Web.Mail" %>
  40. <%
  41. MailMessage msgMail = new MailMessage();
  42.  
  43. msgMail.To = "mailhostingserver@gmail.com";
  44. msgMail.Cc = "testhostingserver@redifffmail.com";
  45. msgMail.From = "sender@yourdomain.com";
  46. msgMail.Subject = "Testing asp.net mail";
  47.  
  48. msgMail.BodyFormat = MailFormat.Html;
  49. string strBody = "<html><body><b>Hello Everyone</b>" +
  50. " <font color=\"red\">ASP.NET</font></body></html>";
  51. msgMail.Body = strBody;
  52.  
  53. SmtpMail.Send(msgMail);
  54.  
  55. Response.Write("Email was queued to disk");
  56. %>
  57. Sending Attachments
  58.  
  59. <% @Page Language="C#" %>
  60. <% @Import Namespace="System.Web.Mail" %>
  61. <%
  62. MailMessage msgMail = new MailMessage();
  63.  
  64. msgMail.To = "mailhostingserver@gmail.com";
  65. msgMail.From = "sender@yourdomain.com";
  66. msgMail.Subject = "Attachment Test";
  67.  
  68. msgMail.BodyFormat = MailFormat.Text;
  69. msgMail.Body = "Check out the attachment!";
  70. msgMail.Attachments.Add(new MailAttachment(Server.MapPath("SimpleMail.aspx")));
  71.  
  72. SmtpMail.Send(msgMail);
  73.  
  74. Response.Write("Email sent....");
  75. %>
Add Comment
Please, Sign In to add comment