Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Simple ASP.NET mail script
- <% @Page Language="C#" %>
- <% @Import Namespace="System.Web.Mail" %>
- <%
- string strTo = "mailhostingserver@gmail.com";
- string strFrom = "sender@yourdomain.com";
- string strSubject = "Hi User";
- SmtpMail.Send(strFrom, strTo, strSubject,
- "A real nice body text here");
- Response.Write("Email was queued to disk");
- %>
- Note: Name the file as <filename>.aspx
- Some other script that worked when the above didnt!
- <% @Page Language="C#" %>
- <% @Import Namespace="System.Net.Mail" %>
- <%
- SmtpClient client = new SmtpClient("localhost");
- MailAddress from = new MailAddress("testing@domainname.tld");
- MailAddress to = new MailAddress("mailhostingserver@gmail.com");
- MailMessage message = new MailMessage(from, to);
- message.Body = "Testing";
- message.BodyEncoding = System.Text.Encoding.ASCII;
- message.Subject = "testing";
- message.SubjectEncoding = System.Text.Encoding.ASCII;
- client.Send(message);
- Response.Write("Email sent");
- %>
- Sending HTML Email
- <% @Page Language="C#" %>
- <% @Import Namespace="System.Web.Mail" %>
- <%
- MailMessage msgMail = new MailMessage();
- msgMail.To = "mailhostingserver@gmail.com";
- msgMail.Cc = "testhostingserver@redifffmail.com";
- msgMail.From = "sender@yourdomain.com";
- msgMail.Subject = "Testing asp.net mail";
- msgMail.BodyFormat = MailFormat.Html;
- string strBody = "<html><body><b>Hello Everyone</b>" +
- " <font color=\"red\">ASP.NET</font></body></html>";
- msgMail.Body = strBody;
- SmtpMail.Send(msgMail);
- Response.Write("Email was queued to disk");
- %>
- Sending Attachments
- <% @Page Language="C#" %>
- <% @Import Namespace="System.Web.Mail" %>
- <%
- MailMessage msgMail = new MailMessage();
- msgMail.To = "mailhostingserver@gmail.com";
- msgMail.From = "sender@yourdomain.com";
- msgMail.Subject = "Attachment Test";
- msgMail.BodyFormat = MailFormat.Text;
- msgMail.Body = "Check out the attachment!";
- msgMail.Attachments.Add(new MailAttachment(Server.MapPath("SimpleMail.aspx")));
- SmtpMail.Send(msgMail);
- Response.Write("Email sent....");
- %>
Add Comment
Please, Sign In to add comment