Sending Mail code in ASP

半腔热情 提交于 2019-12-19 12:28:11

问题


I have given one HTML file. When someone fills the form & sends it, it should send email to their mail id. how to write code for this in ASP?

Your Name:* Email:* Phone No: Your Message:*
  • Gnaniyar Zubair

回答1:


Use CDOSYS like this:-

Dim oMsg : Set oMsg = CreateObject("CDO.Message")

oMsg.From = "Me <me@mymail.myserver.com>"
oMsg.To = "Bloke <bloke@somewere.com>"
oMsg.Subject = "Test"
oMsg.HTMLBody = "<html><body>Hello World</body></html>"

oMsg.Send

Of course you need to get the To field from some persistent store where you store the users profile and supply the Subject and protions of the body from the posted fields.

You also need to configure the mail settings on the IIS application to supply a default configuration for the CDO.Message object. Failing that you need to configure the mail settings yourself using a function like this:-

Function GetConfiguration()
    Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPServerPickupDirectory = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"
    Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"

    Const cdoSendUsingPickup = 1
    Const cdoSendUsingPort = 2

    Dim GetConfiguration : SetGetConfiguration = CreateObject("CDO.Configuration")

    With GetConfiguration.Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "mysmtp.myserver.com"
        .Item(cdoSMTPServerPort) = 25
        .Update
    End With

End Function

Then add this line to the main body of code before calling send:-

Set oMsg.Configuration = GetConfiguration()

Just tweak the the GetConfiguration content to use your SMTP servers host name.

Note don't use CDONTS its deprecated.




回答2:


I assume you are using ASP 3.0, you can use Cdonts.dll

The code:

cBody = Request.Form("Body") 
cPara = = Request.Form("to") 

<%@ Language=VBScript%> 
<html> 

<head> 
   <title>Email Sending</title> 

</head> 
<body>
<% 
Dim cBody, n 

For Each n In Request.Form 
    cBody = cBody & n & ": " & Request.Form(n) & chr(13) 
Next 

Set oCDO = Server.CreateObject("CDONTS.NewMail") 

oCDO.From = "fernan@tudominio.com" 
oCDO.To = "foc@tudominio.com" 
oCDO.Subject = "Subject" 
oCDO.Body = cBody 
'oCDO.Cc = "resal@tudominio.com;webmaster@tudominio.com" 
oCDO.Bcc = "quinqui@tudominio.com" 
'oCDO.MailFormat = 0 

oCDO.Send 

Set oCDO = Nothing 
Response.Write "¡Email Sent!!" 

%> 
</body> 
</html> 


来源:https://stackoverflow.com/questions/772033/sending-mail-code-in-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!