Switch to full style
ASP/ASP.net examples
Post a reply

Send email in asp

Fri Apr 08, 2011 8:41 pm

Send email in asp function creation and call it later in code snippet .
Code:
<html>
<%
 
    
End Sub
Function sendMail
(ByVal mailTo, ByVal mailFrom, ByVal mailSubject, ByVal mailBody)
   
    Dim objMailSender 
= Server.CreateObject("CDONTS.NewMail")
    objMailSender.To = mailTo
    objMailSender
.From = mailFrom
    objMailSender
.Subject = mailSubject
    objMailSender
.Body = mailBody
    objMailSender
.Send()
    objMailSender = Nothing
    If Err Then
        SendMail 
= False
    Else
        SendMail 
= True
    End If
End Function
%> 
 
<p>Calling the send mail function</p>
<%
 
sendMail 
"[email protected]" , "[email protected]" , "Mail Subject" , "Mail Body" 
%>
</
html>
 



You also add attachment to email like this
Code:
<% 
    Dim objMailSender
    
'create an instance of CDONTS 
    objMailSender = Server.CreateObject("CDONTS.NewMail")
    '
From  Email
    objMailSender
.From = "[email protected]"
    'TO Email.
    objMailSender.To = "[email protected]"
    '
Email Subject
    objMailSender
.Subject = "subject:contains attach"
    'File path to be attached 
    objMailSender.AttachFile("c:\img.gif")
    '
Email body
    objMailSender
.Body = "Email body."
    Send the Email
    objMailSender
.Send()
    objMailSender = Nothing
%>
 


You also add HTML to your email body , example
Code:
<% 
    
'create objects.
    Dim objEmailSender, strHTMLContent
    objEmailSender = Server.CreateObject("CDONTS.NewMail")
    '
Add some html 
    strHTMLContent 
= strHTMLContent & "<html><head><title>Title</title></head>"
    strHTMLContent = strHTMLContent & "<body>"
    strHTMLContent = strHTMLContent & "<p>Paragraph part</p>"
    strHTMLContent = strHTMLContent & "<br><hr>"
    strHTMLContent = strHTMLContent & "<b>Bold string</b>"
    strHTMLContent = strHTMLContent & "<a href=""#"">link</a>"
    strHTMLContent = strHTMLContent & "</body></html>"
    'From Email
    objEmailSender.From = "[email protected]"
    '
To Email
    objEmailSender
.To = "[email protected]"
    'Subject
    objEmailSender.Subject = "HTML email"
    '
 The body is HTML content
    objEmailSender
.Body = strHTMLContent
    
    
'Used to format html emails.
    objEmailSender.BodyFormat = 0
    objEmailSender.MailFormat = 0
     
    
    '
Send the Email.
    objEmailSender.Send()
    objEmailSender = Nothing
%>
 




Post a reply
  Related Posts  to : Send email in asp
 Send an email in asp.net     -  
 send email from ASP using CDOSYS     -  
 Send email link example.     -  
 Send Email from a PHP Script Example     -  
 send confirmation link to email     -  
 i want to send conformation email with user details on the     -  
 Send Email Recipient CC,BCC MimeMultipart, Attachments     -  
 validate email address in asp     -  
 email through JAVA program     -  

Topic Tags

ASP Email