Friday, October 21, 2011

Send email using asp

Create an aspx page and Paste this code on the page and change the required credential on the page..


<%@ Language=VBScript %>
<% Option Explicit %>

<%

Dim strFrom
Dim strPassword
Dim strTo
Dim strSubject
Dim strRedirect
Dim strBody
Dim Field
Dim strSubmit
Dim strServer
Dim strThankyou

'=======================================
'---------------------------------------
'        Inside HTML File IMPUT
'---------------------------------------
'<form name = "mail" action="mail.asp" method="POST">
'---------------------------------------
'=======================================
'---------------------------------------
'        Information to Edit
'---------------------------------------
strFrom = "email@domain.com"
strTo = "email@domain.com"
'strTo = "email@domain.com"
strServer = "mail.domain.com"
strThankyou = "thankyou.htm"
'---------------------------------------
' POP/SMTP Password
'---------------------------------------
strPassword = "******"
'=======================================

'strSubject = Request("Subject")
'strSubject = Request("Title of the Paper Presentation")
strRedirect = Request("Redirect")

If Request.QueryString <> "" Then

    'For Each Field in Request.QueryString
        If LCase(Field) <> "Email" And LCase(Field) <> "to" And _
        LCase(Field)<> "subject" And LCase(Field) <> "redirect" And _
        Lcase(Field)<> "submit" Then
            'strBody = strBody & Field & ": " & Request(Field) & chr(13)+ chr(10)
            strbody=strbody&"Name                            :"&Trim(Request("firstname"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Address                    :"&Trim(Request("address"))&"  "&chr(13)+chr(10)
            strbody=strbody&"E-mail                           :"&Trim(Request("email"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Mobile No           :"&Trim(Request("phone"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Zip / Pin code :"&Trim(Request("zip"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Feedback             :"&Trim(Request("feedback"))&"  "&chr(13)+chr(10)
           
        End If
    'Next
   
Else
   

    'For Each Field in Request.Form
       
        If LCase(Field) <> "Email" And LCase(Field) <> "to" And _
        LCase(Field)<> "subject" And LCase(Field) <> "redirect" And _
        Lcase(Field)<> "submit" Then
            'strBody = strBody & Field & ": " & Request(Field) & chr(13)+ chr(10)
            strbody=strbody&"Name                            :"&Trim(Request("firstname"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Address                    :"&Trim(Request("address"))&"  "&chr(13)+chr(10)
            strbody=strbody&"E-mail                           :"&Trim(Request("email"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Mobile No           :"&Trim(Request("phone"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Zip / Pin code  :"&Trim(Request("zip"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Feedback             :"&Trim(Request("feedback"))&"  "&chr(13)+chr(10)
           
           
        End If
       
    'Next


End If

SendMail strFrom,strTo,strSubject,strBody,strServer,strThankyou,strPassword

%>


<%

Sub SendMail(strFrom,strTo,strSubject,strBody,strServer,strThankyou,strPassword)

On Error Resume Next

Dim Mailer
Set Mailer = server.createobject("CDO.Message")

Mailer.From = strFrom
Mailer.To = strTo
Mailer.TextBody = strBody
Mailer.Subject = "Contact Information"
'Mailer.Subject = request("sub")
With Mailer.Configuration
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'------------------------------------------------------------------------------
' For SMTP Authentication Modify ('.Fields) to (.Fields) for three fields Below
'------------------------------------------------------------------------------
'.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = strFrom
'.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
'------------------------------------------------------------------------------
.Fields.Update
End With

Mailer.Send
Set Mailer = Nothing

If Err.number<>0 Then
    Response.Write Err.Description
    Response.End
End If

Response.Redirect str Thankyou

End Sub

%>

No comments:

Post a Comment