Archive for the 'aspmail' Category

Apr 22

Mailing Scripts

No comment - Post a comment

Mailing Scripts

You can use any of the following scripts in your website coding to send mails thru your website from any of WIPL Windows Server. The following scripts make your life very easy when you trying to send mails from your website.

* CDOSYS

<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<%
‘Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject(“CDO.Message”)
Set objCDOSYSCon = Server.CreateObject (“CDO.Configuration”)
‘ Outgoing SMTP server
objCDOSYSCon.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “localhost”
objCDOSYSCon.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objCDOSYSCon.Fields(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
objCDOSYSCon.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
objCDOSYSCon.Fields.Update

‘ Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = “user1@yourdomain.com”
objCDOSYSMail.To = “user2@yourdomain.com”
objCDOSYSMail.Subject = “CDOSYS is running, Check your code”
objCDOSYSMail.HTMLBody = “This is the body ”
objCDOSYSMail.Send
‘Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Email</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body>
Email has sent!
</body>
</html>

* Cdonts

<%
Dim myMail
Set myMail = Server.CreateObject (“CDONTS.NewMail”)
myMail.From = “user1@domain.com”
myMail.To = “user2@domain.com”
myMail.Subject = “Test email using CDONTS”
myMail.Body = “This is a test email message” & vbcrlf & “sent with CDONTS”
myMail.Send
set myMail=nothing
Response.Write(“Your e-mail has been sent”)
%>

* Jmail Script

<%
Dim MyMail
Set MyMail = Server.CreateObject(“JMail.SMTPMail”)
MyMail.ServerAddress = “localhost”
MyMail.Sender = “user@domain.com
MyMail.AddRecipient “user11@domain.com
MyMail.Subject = “Test Email using Jmail”
MyMail.Body = “This is a test email message” & vbcrlf & “sent with Jmail”
MyMail.Execute
Set myMail=nothing
Response.Write(“Your e-mail has been sent”)
%>

* Persist ASP Mail

First create form.html

<html>
<head>
<title></title>
</head>

<body>

<form action=”sendmail.asp” method=”post”>
<input type=”hidden” name value><table border=”0″ cellpadding=”0″ cellspacing=”0″
width=”0%”>
<tr>
<td width=”0%” align=”left”><font face=”Arial” size=”2″><strong>Name </strong></font></td>
<td width=”0%”><input type=”text” name=”name” size=”20″></td>
</tr>
<tr>
<td width=”0%” align=”left”><font face=”Arial” size=”2″><strong>Address </strong></font></td>
<td width=”0%”><input type=”text” name=”address” size=”30″></td>
</tr>
<tr>
<td width=”0%” align=”left”><font face=”Arial” size=”2″><strong>Phone</strong></font></td>
<td width=”0%”><input type=”text” name=”phone” size=”30″></td>
</tr>
<tr>
<td width=”0%” align=”left”><font face=”Arial” size=”2″><strong>E-mail</strong></font></td>
<td width=”0%”><input type=”text” name=”email” size=”15″></td>
</tr>
</table>
<table>
<tr>
<td width=”0%” align=”left”><input type=”submit” value=”Submit”> </td>
</tr>
</table>
</form>
</body>
</html>

Now Create sendmail.asp

<html>
<head>
<title></title>
</head>
<body bgcolor=”#FFFFFF”>
<%
phone = request.form(“phone”)
email = request.form(“email”)
name = request.form(“name”)
address = request.form(“address”)

IF ((name=”") or (email=”")) THEN
ErrMsg = “Please enter your name and/or e-mail address”
ELSE
Set Mail = Server.CreateObject(“Persits.MailSender”)
Mail.Host = “mail.domain.com”
Mail.From = email ‘Note: Must be someuser@yourdomain.com
Mail.FromName = name

‘ The User and Password below is required by ASPEmail to get by our SMTP Authentication

Mail.Username = “user@domain.com”
Mail.Password = “password”

Mail.AddAddress “user@domain.com”, “test”
Mail.AddReplyTo email
Mail.Subject = “test”

BodyMsg = “Requested Information: ” + Chr(50)
BodyMsg = BodyMsg + “Name = ” & name & Chr(50)
BodyMsg = BodyMsg + “Address = ” & address & Chr(50)
BodyMsg = BodyMsg + “Phone: ” & phone & Chr(50)
BodyMsg = BodyMsg + “Email = ” & email & Chr(50)

Mail.Body = BodyMsg

On Error Resume Next
Mail.Send
If Err <> 0 Then
ErrMsg = “Your request was not sent due to the following error: ” & Err.Description
Else
ErrMsg = “Thank You For filling our form<BR>”
ErrMsg = ErrMsg + “If you have any questions please e-mail us.”
End If
End If
%>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ width=”0%”>
<tr>
<td width=”100%” align=”center”><hr width=”90%”>
</td>
</tr>
<tr>
<tr>
<td align=”center”><font face=”Arial” size=”2″><strong><%=ErrMsg%></strong></font></td>
</tr>
<tr>
</tr>
</table>
</body>
</html>

* PHP Mailing Script

<?php
$to = ‘user@domain.com’;
$subject = ‘PHP MAIL’;
$from = ‘user1@domain.com’;
$message = ‘PHP MAIL TESTING’;
if(mail($to, $subject, $message, “From: $from”))
echo “Mail sent”;
else
echo “Mail send failure – message not sent”; ?>

* ASPX Mailing Script

<%@ Import Namespace=”System.Net” %>
<%@ Import Namespace=”System.Net.Mail” %>
<html>
<script language=”C#” runat=”server”>
void Page_Load()
{
if (!IsPostBack)
{
}
}
void btnSubmit_Click(Object sender, EventArgs e)
{
// Command line argument must the the SMTP host.
SmtpClient client = new SmtpClient();
// set SMTP client settings
client.Host = txtMailServer.Text.Trim();
client.Port = Int32.Parse(txtMailPort.Text.Trim());
if (String.IsNullOrEmpty(txtUsername.Text))
{
client.Credentials = new NetworkCredential(txtUsername.Text, txtPassword.Text);
}
// create message
MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text);
message.Body = txtBody.Text;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.Subject = txtSubject.Text;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// send message
try
{
client.Send(message);
lblMsg1.Text = “Message has been sent”;
}
catch (SmtpException ex)
{
lblMsg1.Text = “<pre>” + ex.ToString() + “</pre>”;
}
finally
{
// Clean up.
message.Dispose();
}
}
</script>
<body>
<p><h4>Send a new mail message:<h4></p>
<Form method=”Post” action=”MailForm.aspx” runat=”server”>
<table width=”350″ bgcolor=”#FFFF99″>
<tr>
<td Align=”Right”><b>From:</b></td>
<td><Asp:Textbox id=”txtFrom” runat=”server”>mail@domain.com</Asp:Textbox></td>
</tr>
<tr>
<td Align=”Right”><b>To:</b></td>
<td><Asp:Textbox id=”txtTo” runat=”server”>somebody@mail.com</Asp:Textbox></td>
</tr>
<tr>
<td Align=”Right”><b>Subject:</b></td>
<td><Asp:Textbox id=”txtSubject” runat=”server”>Test</Asp:Textbox></td>
</tr>
<tr>
<td Align=”Right”><b>Body:</b></td>
<td><Asp:Textbox id=”txtBody” runat=”server” Rows=”5″ TextMode=”MultiLine”>Test</Asp:Textbox></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td Align=”Right”><b>Mail Server:</b></td>
<td><Asp:Textbox id=”txtMailServer” runat=”server”>64.187.104.83</Asp:Textbox></td>
</tr>
<tr>
<td Align=”Right”><b>Mail Port:</b></td>
<td><Asp:Textbox id=”txtMailPort” runat=”server”>25</Asp:Textbox></td>
</tr>
<tr>
<td Align=”Right”><b>Username:</b></td>
<td><Asp:Textbox id=”txtUsername” runat=”server”/></td>
</tr>
<tr>
<td Align=”Right”><b>Password:</b></td>
<td><Asp:Textbox id=”txtPassword” runat=”server”/></td>
</tr>
</table><br>
<asp:button id=”btnSubmit” Text=”Send Mail” OnClick=”btnSubmit_Click” runat=”server”/>
<p><asp:Label id=”lblMsg1″ runat=”server”/></p>
</form>
</body>
</html>

* Dundas Mailing Script

The first thing you need to do is create a formpage.asp page with the code below:

<form name=”YourFormName” method=”Post” action=”confirmation.asp”>
<table>
<tr><td>Email: </td>
<td><input type=”text” name=”Email” size=”50″></td></tr>
<tr><td>First Name: </td>
<td><input type=”text” name=”FirstName” size=”50″></td></tr>
<tr><td>Last Name: </td>
<td><input type=”text” name=”LastName” size=”50″></td></tr>
<tr><td>Subject: </td>
<td><input type=”text” name=”Subject” size=”50″></td></tr>
<tr><td>Comments: </td>
<td><textarea name=”Comments”></textarea></td>
</table>
<input type=”submit” name=”Submit” value=”Submit Form”>
</form>

Next, we create a confirmation.asp page and enter the code as seen below:

<%
DIM strEmail, strFirstName, strLastName, strSubject, strComments, Mailer
strEmail = Request.Form(“Email”)
strFirstName = Request.Form(“FirstName”)
strLastName = Request.Form(“LastName”)
strSubject = Request.Form(“Subject”)
strComments = Request.Form(“Comments”)

DIM objMailer
intSubscribers = 0
DO WHILE NOT objRSs.EOF
Set objMailer = Server.CreateObject (“Dundas.Mailer”)
strSubscriber = objRSs(“fSubscriber”)
objMailer.SMTPRelayServers.Add = strMailHost
objMailer.FromAddress = strEmail
objMailer.FromName = strFromName
objMailer.TOs.Add strToName & “<” & strSubscriber & “>”
objMailer.Subject = strSubject
objMailer.Body = strComments
objMailer.SendMail
Set objMailer = Nothing
%>

Now you have a complete form that sends data to an email address and displays a customized message for your user. The default for Dundas like the other mail components we cover is to send text messages. If you want to send HTML messages you can simply include this extra line of code before the objMailer.Body line.

objMailer.ContentType = “text/html”