Trimiterea de emailuri prin autentificare SMTP folosind ASP se poate face cu codul de mai jos:

<%
Dim intError
Dim strResult
Function SendMail(SMTPServer, SMTPUserName, SMTPPassword, EMailFrom, EMailTo, EMailCc, EMailBcc, EMailSubject, EMailType, EMailContent)
Dim cdoConfig
Dim cdoMessage
Dim intErr

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = SMTPServer
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUsername) = SMTPUserName
.Item(cdoSendPassword) = SMTPPassword
.Update
End With

Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
If Len(Trim(CStr(EMailFrom))) = 0 Then
.From = SMTPUserName
Else
.From = EMailFrom
End If
.To = EMailTo
If Len(Trim(CStr(EMailCc))) <> 0 Then .Cc = EMailCc
If Len(Trim(CStr(EMailBcc))) <> 0 Then .Bcc = EMailBcc
.Subject = EmailSubject
If EMailType = "text" Then
.TextBody = EMailContent
ElseIf EMailType = "html" Then
.HTMLBody = EMailContent
End If
.Send

intErr = Err.Number
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing

SendMail = intErr
Session("ErrDescription")=Err.Description
End Function

intError = SendMail("your-mailserver-ip", "[email protected]", "smtp-password", "send-from-email", "send-to-email", "send-cc-email", "send-bcc-email", "email-subject", "text", "email-body")
If intError = 0 Then
'No errors, mail sent
strResult = "The mail has been sent successfully."
Else
strResult = "There was a problem sending the mail"
End if
Response.Write(strResult)
%>

Răspunsul a fost util? 79 utilizatori au considerat informația utilă (227 Voturi)