-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJangoSMTP.aspx
More file actions
61 lines (50 loc) · 2.08 KB
/
JangoSMTP.aspx
File metadata and controls
61 lines (50 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<%@ Page Language="C#" %>
<%@ Import namespace="System.Net.Mime" %>
<%@ Import namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SendTestEmail();
}
// this routine demonstrates sending smtp mail using JangoSMTP in ASP.Net
void SendTestEmail()
{
try
{
MailMessage mailMsg = new MailMessage();
// To
mailMsg.To.Add(new MailAddress("ToAddress@Domain.com", "Recipient Name"));
// set the from address
// this must be stored in your from addresses
mailMsg.From = new MailAddress("YourEmail@YourDomain.com", "Your Name");
// set the subject and message portions of the email
mailMsg.Subject = "Test Email Subject";
string text = "This plain text email was sent from an ASP.Net script.";
string html = @"<p>This html email was sent from an ASP.Net script.</p>";
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));
// set up the SMTP client with relay.jangosmtp.net
SmtpClient smtpClient = new SmtpClient("relay.jangosmtp.net", Convert.ToInt32(25));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("Your JangoSMTP Username", "Your JangoSMTP Password");
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
Result.InnerHtml = "Mail sent!";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="Result" runat="server">
</div>
</form>
</body>
</html>