TLS使用传统的ASP发送邮件 [英] Tls using classic asp to send mail

查看:445
本文介绍了TLS使用传统的ASP发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时的任何可能使用TLS使用的是免费的lib使用ASP经典发送邮件?

我用CDO,但我认为这不会允许TLS。

感谢所有,并为问题抱歉。我可以使用Gmail发送没有问题的邮件,但现在我需要使用服务器,只允许TLS身份验证来发送邮件。我不觉得在API或互联网的方式使用TLS来发送邮件。

功能bCorreoEnviarGeneral(objCorreo,bPorSeparado,体感诱发电位,sMailFrom,sMailTo,sAsunto,sCuerpo,SBCC,sAdjunto)
朦胧I,J,iNumDest
暗淡bSalida
梅勒暗淡
暗淡arrayMailTo
暗淡objMessage
暗淡ArrayBCC
朦胧MAILFROM,mailSmtp,mailuser的,mailPassword,mailSSL,mailPort调用DatosServidorCorreo(MAILFROM,mailSmtp,mailuser的,mailPassword,mailSSL,mailPort)在错误恢复下一个   常量cdoSendUsingPickup = 1'使用本地SMTP服务拾取目录发送信息。
   常量cdoSendUsingPort = 2'发送使用网络(SMTP通过网络)的消息。  常量cdoAnonymous = 0'不验证
  常量cdoBasic = 1'的基本(明文)身份验证
  常量cdoNTLM = 2'NTLM  设置objMessage =的CreateObject(CDO.Message)
  objMessage.Subject = sAsunto
  objMessage.From =SIG如果sMailFrom<>中,然后
    objMessage.From = sMailFrom
其他
    objMessage.From = MAILFROM
万一 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/sendusing)= 2 名称或远程SMTP服务器的IP
 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/smtpserver)= mailSmtp
 认证类型:None,基本的(Base64 EN codeD),NTLM
 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/smtpauthenticate)= cdoBasic
 '您的用户名SMTP服务器上
 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/sendusername)= mailuser的
 SMTP服务器上的您的密码
 objMessage.Configuration.Fields.Item _
  (http://schemas.microsoft.com/cdo/configuration/sendpassword)= mailPassword服务器端口(通常为25)
 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/smtpserverport)= mailPort 使用SSL连接(False或True)
 objMessage.Configuration.Fields.Item _
 (http://schemas.microsoft.com/cdo/configuration/smtpusessl)= mailSSL在几秒钟内连接超时(最大时间CDO将尝试建立到SMTP服务器的连接)
objMessage.Configuration.Fields.Item _
(http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout)= 60objMessage.Configuration.Fields.Update '==结束远程SMTP服务器配置部分==如果INSTR(LCASE(sCuerpo),&所述; HTML>中)所述​​;大于0则
    objMessage.HTMLBody = sCuerpo
其他
    objMessage.TextBody = sCuerpo
万一如果sAdjunto<>中,然后
arrayAdjuntos =斯普利特(Adjunto,SSEP)
'对于i = 0至UBOUND(arrayAdjuntos)
      objMessage.AddAttachment sAdjunto'arrayAdjuntos(I)
' 下一个
万一如果会议(idpersona)= 1038,然后
   如果sAdjunto<>中,然后回复于< BR>中+ sAdjunto +< BR>中
万一
    arrayMailTo =斯普利特(sMailTo,SSEP)
    iNumDest = UBOUND(arrayMailTo)如果iNumDest< 0,则
    objMessage.To = sMailFrom
    objMessage.Send    如果Err.Number的= 0则
       如果propCorreoVerMensajes然后回复于邮件enviado ......
      其他
      bSalida = FALSE
      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将+ mailSmtp
    万一ELSEIF bPorSeparado然后
  对于i = 0至iNumDest   objMessage.To = arrayMailTo(I)    若i = iNumDest和修剪(SBCC)LT;>中,然后
       arrayBCC =斯普利特(SBCC,SSEP)
       对于j = 0到UBOUND(arrayBCC)
          objMessage.BCC = arrayBCC(J)
       下一个
    万一    objMessage.Send
    如果Err.Number的= 0则
      如果propCorreoVerMensajes然后回复于邮件enviado ......
       其他
      bSalida = FALSE
      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
    万一
  下一个
     其他  如果TRIM(SBCC)LT;>中,然后
     arrayBCC =斯普利特(SBCC,SSEP)
     对于i = 0至UBOUND(arrayBCC)
      objMessage.BCC = arrayBCC(I)
     下一个
  万一  对于i = 0至iNumDest
    objMessage.To = arrayMailTo(I)
  下一个在错误恢复下一个  objMessage.Send  如果Err.Number的= 0则
    如果propCorreoVerMensajes然后回复于邮件enviado ......
  其他
     bSalida = FALSE
     的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
  万一
对错误转到0
   万一   设置objMessage =什么 bCorreoEnviarGeneral = TRUE
  结束功能


解决方案

通过这个code你允许,使用SSL,TLS发送,没有他们,附加一个文件,发送到数倍地址,发送无BCC ... ..唯一的问题是,你需要使用薪酬ASPemail库。

 函数DatosServidorCorreo(MAILFROM,mailSmtp,mailuser的,mailPassword,mailTLS,mailPort,mailSSL)
昏暗的SQL,章
设置BD =会议(参数conn)BD =供应商= MSDASQL.1;数据源= dsnSig;扩展属性= CHR(39)DSN = dsnSig; DBQ = C:\\ BD \\ SIG_Tecnoy_BBDD.mdb; DriverId = 25; FIL = MS访问; MAXBUFFERSIZE = 2048;将PageTimeout = 5; CHR(39)
SQL =选择SIG_PARAMETROS *
如果不是BDRegCrear(BD,章,SQL),那么
    调用dialogo(错误conexiónBD)
    调用BDErrorMostrar(无SE puede acceder洛DATOS德尔servidor)
    DatosServidorCorreo = FALSE
    退出功能
万一这样做虽然不reg.eof
    如果TRIM(reg.fields(农布雷))=的MailFrom,那么
        MAILFROM =修剪(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=MailSmtp,那么
        mailSmtp =修剪(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=mailuser的再
        mailuser的修剪=(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=MailPassword,那么
        mailPassword =修剪(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=MailTLS,那么
        mailTLS =修剪(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=MailPort,那么
        mailPort =修剪(reg.fields(勇气))
    ELSEIF修剪(reg.fields(农布雷))=MailSSL,那么
        mailSSL =修剪(reg.fields(勇气))
    万一
    reg.movenext
循环设置BD =什么调用BDRegLiberar(REG)
最终功能
   功能bCorreoEnviarGeneral(objCorreo,bPorSeparado,体感诱发电位,sMailFrom,sMailTo,sAsunto,sCuerpo,SBCC,sAdjunto)
朦胧I,J,iNumDest
暗淡bSalida
暗淡objMessage
昏暗的邮件
朦胧MAILFROM,mailSmtp,mailuser的,mailPassword,mailTLS,mailPort,mailSSL调用DatosServidorCorreo(MAILFROM,mailSmtp,mailuser的,mailPassword,mailTLS,mailPort,mailSSL)在错误恢复下一个
  如果(mailTLS =真),那么    Envio德邮报CON encriptacion TLS
    bSalida =真
    设置邮件=的Server.CreateObject(Persits.MailSender)
    Mail.Host = mailSmtp
    Mail.Username = mailuser的
    Mail.Password = mailPassword
    Mail.Port = mailPort
    Mail.TLS = mailTLS
    Mail.Subject = sAsunto
    Mail.AddAddress sMailTo
    Mail.From = MAILFROM        思曼达EL SISTEMA EL邮报报remitente血清EL recogido EN LA BBDD,SI EL remitente上课联合国usuario EL remitente血清ESE usuario        如果sMailFrom<>中,然后                Mail.From = sMailFrom
        其他                Mail.From = MAILFROM
        万一        洛杉矶mensajes pueden红外连接texto平Ø连接formato HTML CON EL siguiente IF SI EL mensaje ES HTML种下atribuye一拉propiedad booleana IsHTML EL勇气真(假POR defecto连接texto平)
        如果INSTR(LCASE(sCuerpo),&所述; HTML>中)所述​​;大于0则            Mail.IsHTML = TRUE
            Mail.Body = sCuerpo
        其他            Mail.Body = sCuerpo
        万一        Sistema的德archivos adjuntos(独奏UNO的Máximo科莫POR邮报)        如果sAdjunto<>中,然后
                Mail.AddAttachment sAdjunto
        万一
        arrayMailTo =斯普利特(sMailTo,SSEP)
        iNumDest = UBOUND(arrayMailTo)
如果会议(idpersona)= 1038,然后
   如果sAdjunto<>中,然后回复于< BR>中+ sAdjunto +< BR>中
万一
    arrayMailTo =斯普利特(sMailTo,SSEP)
    iNumDest = UBOUND(arrayMailTo)如果iNumDest< 0,则    Mail.AddAddress sMailFrom
    Mail.Send    如果Err.Number的= 0则
       如果propCorreoVerMensajes然后回复于邮件enviado ......
    其他
      bSalida = FALSE
      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将+ mailSmtp
    万一ELSEIF bPorSeparado然后  对于i = 0至iNumDest
        啪啦CADA UNO德洛斯destinatarios EN LAmatríz,enviamos联合国mensaje
   Mail.AddAddress arrayMailTo㈠
    硅本身envian洛杉矶邮件POR separado,独唱本身ENVIA CON COPIA EL Ultimo的,porque中
    洛destinatarios连接SBCC莱llegaríanñ西班牙邮政repetidos:
    硒añaden洛杉矶密件抄送连接埃尔Ultimo的puesto阙没有干草posibilidad CON ESTE objeto德borrar(清)
    厄尔尼诺recipiente日密件。
    若i = iNumDest和修剪(SBCC)LT;>中,然后
       arrayBCC =斯普利特(SBCC,SSEP)
       对于j = 0到UBOUND(arrayBCC)
          Mail.AddBcc arrayBCC(J)
       下一个
    万一    Mail.Send    如果Err.Number的= 0则
      如果propCorreoVerMensajes然后回复于邮件enviado ......
    其他
      bSalida = FALSE      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
    万一
  下一个
      其他
  Destinatarios CON COPIA:
  如果TRIM(SBCC)LT;>中,然后     arrayBCC =斯普利特(SBCC,SSEP)
     对于i = 0至UBOUND(arrayBCC)
      Mail.AddBcc arrayBCC㈠
     下一个
  万一    Mail.AddAddress sMailTo
在错误恢复下一个  Mail.Send  如果Err.Number的= 0则
    如果propCorreoVerMensajes然后回复于邮件enviado ......
  其他
     bSalida = FALSE
     的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
  万一
对错误转到0
万一
设置邮件=什么
    其他        Mensaje CON encriptacion SSLØ自由报德艾拉。
        bSalida =真
        常量cdoSendUsingPickup = 1'使用本地SMTP服务拾取目录发送信息。
        常量cdoSendUsingPort = 2'发送使用网络(SMTP通过网络)的消息。        常量cdoAnonymous = 0'不验证
        常量cdoBasic = 1'的基本(明文)身份验证
        常量cdoNTLM = 2'NTLM        设置objMessage =的CreateObject(CDO.Message)
        objMessage.Subject = sAsunto
        objMessage.To = sMailTo
        如果sMailFrom<>中,然后                objMessage.From = sMailFrom
        其他                objMessage.From = MAILFROM
        万一        objMessage.Configuration.Fields.Item _
        (http://schemas.microsoft.com/cdo/configuration/sendusing)= 2                 名称或远程SMTP服务器的IP
   objMessage.Configuration.Fields.Item _
   (http://schemas.microsoft.com/cdo/configuration/smtpserver)= mailSmtp
  认证类型:None,基本的(Base64 EN codeD),NTLM
   objMessage.Configuration.Fields.Item _
     (http://schemas.microsoft.com/cdo/configuration/smtpauthenticate)= cdoBasic
     '您的用户名SMTP服务器上
    objMessage.Configuration.Fields.Item _
     (http://schemas.microsoft.com/cdo/configuration/sendusername)= mailuser的
      SMTP服务器上的您的密码
    objMessage.Configuration.Fields.Item _
    (http://schemas.microsoft.com/cdo/configuration/sendpassword)= mailPassword    服务器端口(通常为25)
  objMessage.Configuration.Fields.Item _
    (http://schemas.microsoft.com/cdo/configuration/smtpserverport)= mailPort   使用SSL连接(False或True)
  objMessage.Configuration.Fields.Item _
    (http://schemas.microsoft.com/cdo/configuration/smtpusessl)= mailSSL objMessage.Configuration.Fields.Item _
  (http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout)= 120      objMessage.Configuration.Fields.Update    '==结束远程SMTP服务器配置部分==如果INSTR(LCASE(sCuerpo),&所述; HTML>中)所述​​;大于0则
    objMessage.HTMLBody = sCuerpo
其他
    objMessage.TextBody = sCuerpo
万一如果sAdjunto<>中,然后
arrayAdjuntos =斯普利特(Adjunto,SSEP)
'对于i = 0至UBOUND(arrayAdjuntos)
      objMessage.AddAttachment(sAdjunto)'arrayAdjuntos(I)
' 下一个
万一如果会议(idpersona)= 1038,然后
   如果sAdjunto<>中,然后回复于< BR>中+ sAdjunto +< BR>中
万一
    arrayMailTo =斯普利特(sMailTo,SSEP)
    iNumDest = UBOUND(arrayMailTo)如果iNumDest< 0,则
    objMessage.To = sMailFrom
    objMessage.Send    如果Err.Number的= 0则
       如果propCorreoVerMensajes然后回复于邮件enviado ......
    其他
      bSalida = FALSE
      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将+ mailSmtp
    万一ELSEIF bPorSeparado然后
  对于i = 0至iNumDest
        啪啦CADA UNO德洛斯destinatarios EN LAmatríz,enviamos联合国mensaje
   objMessage.To = arrayMailTo(I)
    硅本身envian洛杉矶邮件POR separado,独唱本身ENVIA CON COPIA EL Ultimo的,porque中
    洛destinatarios连接SBCC莱llegaríanñ西班牙邮政repetidos:
    硒añaden洛杉矶密件抄送连接埃尔Ultimo的puesto阙没有干草posibilidad CON ESTE objeto德borrar(清)
    厄尔尼诺recipiente日密件。
    若i = iNumDest和修剪(SBCC)LT;>中,然后
       arrayBCC =斯普利特(SBCC,SSEP)
       对于j = 0到UBOUND(arrayBCC)
          objMessage.BCC = arrayBCC(J)
       下一个
    万一    objMessage.Send
    如果Err.Number的= 0则
      如果propCorreoVerMensajes然后回复于邮件enviado ......
    其他
      bSalida = FALSE
      的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
    万一
  下一个
  其他  Destinatarios CON COPIA:
  如果TRIM(SBCC)LT;>中,然后
     arrayBCC =斯普利特(SBCC,SSEP)
     对于i = 0至UBOUND(arrayBCC)
      objMessage.BCC = arrayBCC(I)
     下一个
  万一
    objMessage.To = sMailTo在错误恢复下一个  objMessage.Send  如果Err.Number的= 0则
    如果propCorreoVerMensajes然后回复于邮件enviado ......
  其他
     bSalida = FALSE
     的Response.WriteEnvío去邮件fallido。厄尔尼诺错误ES+ Err.Description它将
  万一
对错误转到0
万一
设置objMessage =什么    万一    bCorreoEnviarGeneral = bSalida 结束功能

Is any possibility to use TLS to send mail using ASP classic using a free lib?

I have used CDO but i think that not allow TLS.

Thanks for all, and sorry for the question. I can send mail using Gmail without problem, but now i need to send mail using a server that only allow Tls authentication. I dont find in the api or in internet the way to send a mail using TLS.

    Function bCorreoEnviarGeneral(objCorreo, bPorSeparado, sSep, sMailFrom, sMailTo, sAsunto, sCuerpo, sBCC, sAdjunto)
dim i,j,iNumDest
dim bSalida
dim Mailer
dim arrayMailTo
dim objMessage
dim ArrayBCC
dim mailFrom,mailSmtp,mailUser,mailPassword,mailSSL,mailPort

call DatosServidorCorreo (mailFrom,mailSmtp,mailUser,mailPassword,mailSSL,mailPort)

on error resume next

   Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
   Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

  Const cdoAnonymous = 0 'Do not authenticate
  Const cdoBasic = 1 'basic (clear-text) authentication
  Const cdoNTLM = 2 'NTLM

  Set objMessage = CreateObject("CDO.Message")
  objMessage.Subject = sAsunto
  objMessage.From = "SIG"

if sMailFrom<>"" then
    objMessage.From  = sMailFrom
else
    objMessage.From  = mailFrom
end if

 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

 'Name or IP of Remote SMTP Server
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailSmtp
 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
 'Your UserID on the SMTP server
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUser
 'Your password on the SMTP server
 objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword

'Server port (typically 25)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mailPort

 'Use SSL for the connection (False or True)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mailSSL

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection      to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

 '==End remote SMTP server configuration section==

if instr(lcase(sCuerpo),"<html>")<>0 then 
    objMessage.HTMLBody = sCuerpo
else
    objMessage.TextBody = sCuerpo
end if

if sAdjunto<>"" then
'      arrayAdjuntos = Split(Adjunto,sSep)
'      for i=0 to uBound(arrayAdjuntos)
      objMessage.AddAttachment sAdjunto 'arrayAdjuntos(i)
'     next
end if

if session("idpersona")=1038 then
   if sAdjunto<>"" then Response.Write "<br>"+sAdjunto+"<br>"
end if
    arrayMailTo = Split(sMailTo,sSep)
    iNumDest = ubound(arrayMailTo)

if iNumDest < 0 then
    objMessage.To = sMailFrom
    objMessage.Send 

    if err.number = 0 then
       'if propCorreoVerMensajes then Response.Write "Mail enviado..."
      else
      bSalida = false
      Response.Write "Envío de mail fallido. El error es " + err.description + mailSmtp
    end if

elseif bPorSeparado then


  for i=0 to iNumDest

   objMessage.To = arrayMailTo(i)

    if i=iNumDest and trim(sBCC)<>"" then
       arrayBCC = Split(sBCC,sSep)
       for j=0 to uBound(arrayBCC)
          objMessage.BCC  = arrayBCC(j)
       next
    end if

    objMessage.Send 
    if err.number = 0 then
      ' if propCorreoVerMensajes then Response.Write "Mail enviado..."
       else
      bSalida = false
      Response.Write "Envío de mail fallido. El error es " + err.description
    end if
  next
     else

  if trim(sBCC)<>"" then
     arrayBCC = Split(sBCC,sSep)
     for i=0 to uBound(arrayBCC)
      objMessage.BCC = arrayBCC(i)
     next
  end if

  for i=0 to iNumDest
    objMessage.To = arrayMailTo(i)
  next

on error resume next

  objMessage.Send 

  if err.number = 0 then
    'if propCorreoVerMensajes then Response.Write "Mail enviado..."
  else
     bSalida = false
     Response.Write "Envío de mail fallido. El error es " + err.description
  end if
on error goto 0
   end if

   set objMessage = nothing

 bCorreoEnviarGeneral = True
  End Function

解决方案

With this code you allow, send with SSL, TLS, without them, attach one file, send to multiples address, send without BCC..... the only problem is that you need to use ASPemail lib of pay.

function DatosServidorCorreo(mailFrom,mailSmtp,mailUser,mailPassword,mailTLS,mailPort,mailSSL)
dim sql,reg


set BD=session("conn")

'BD="Provider=MSDASQL.1;Data Source=dsnSig;Extended Properties=Chr(39)DSN=dsnSig;DBQ=C:\bd\SIG_Tecnoy_BBDD.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;Chr(39)"
sql="select * from SIG_PARAMETROS"
if not BDRegCrear(BD,reg,sql) then
    call dialogo ("Error conexión BD")
    call BDErrorMostrar("No se puede acceder a los datos del servidor")
    DatosServidorCorreo=false
    exit function
end if

do while not reg.eof
    if trim(reg.fields("Nombre")) = "MailFrom" then 
        mailFrom = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailSmtp" then
        mailSmtp = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailUser" then
        mailUser = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailPassword" then
        mailPassword = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailTLS" then
        mailTLS = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailPort" then
        mailPort = trim(reg.fields("Valor"))
    elseif trim(reg.fields("Nombre")) = "MailSSL" then
        mailSSL = trim(reg.fields("Valor"))
    end if
    reg.movenext
loop

set BD=nothing

call BDRegLiberar(reg)
end function


   Function bCorreoEnviarGeneral(objCorreo, bPorSeparado, sSep, sMailFrom, sMailTo, sAsunto, sCuerpo, sBCC, sAdjunto)
dim i,j,iNumDest
dim bSalida
dim objMessage
dim Mail
dim mailFrom,mailSmtp,mailUser,mailPassword,mailTLS,mailPort,mailSSL

call DatosServidorCorreo (mailFrom,mailSmtp,mailUser,mailPassword,mailTLS,mailPort,mailSSL)

on error resume next


  if (mailTLS = "True" ) then

    ' Envio de correo con encriptacion TLS


    bSalida = true
    Set Mail = Server.CreateObject("Persits.MailSender")
    Mail.Host = mailSmtp
    Mail.Username = mailUser
    Mail.Password = mailPassword
    Mail.Port= mailPort
    Mail.TLS = mailTLS
    Mail.Subject = sAsunto
    'Mail.AddAddress sMailTo
    Mail.From  = mailFrom

        ' Si manda el sistema el correo el remitente será el recogido en la BBDD, si el remitente es un usuario el remitente será ese usuario

        if sMailFrom<>"" then

                Mail.From  = sMailFrom
        else

                Mail.From  = mailFrom
        end if

        ' Los mensajes pueden ir en texto plano o en formato html con el siguiente IF si el mensaje es HTML se le atribuye a la propiedad booleana IsHTML el valor True (False por      defecto en texto plano)


        if instr(lcase(sCuerpo),"<html>")<>0 then 

            Mail.IsHTML = True
            Mail.Body = sCuerpo
        else

            Mail.Body = sCuerpo
        end if

        ' Sistema de archivos adjuntos (Solo uno como máximo por correo)

        if sAdjunto<>"" then
                Mail.AddAttachment sAdjunto 
        end if


        arrayMailTo = Split(sMailTo,sSep)
        iNumDest = ubound(arrayMailTo)


if session("idpersona")=1038 then
   if sAdjunto<>"" then Response.Write "<br>"+sAdjunto+"<br>"
end if
    arrayMailTo = Split(sMailTo,sSep)
    iNumDest = ubound(arrayMailTo)

if iNumDest < 0 then

    Mail.AddAddress sMailFrom
    Mail.Send 

    if err.number = 0 then
       'if propCorreoVerMensajes then Response.Write "Mail enviado..."
    else
      bSalida = false
      Response.Write "Envío de mail fallido. El error es " + err.description + mailSmtp
    end if

elseif bPorSeparado then



  for i=0 to iNumDest
        'Para cada uno de los destinatarios en la matríz, enviamos un mensaje
   Mail.AddAddress arrayMailTo(i)
    'Si se envian los mails por separado, sólo se envia con copia el último, porque sino
    'a los destinatarios en sBCC les llegarían n correos repetidos:
    'Se añaden los Bcc en el último puesto que no hay posibilidad con éste objeto de borrar(clear)
    'el recipiente de Bcc.
    if i=iNumDest and trim(sBCC)<>"" then
       arrayBCC = Split(sBCC,sSep)
       for j=0 to uBound(arrayBCC)
          Mail.AddBcc arrayBCC(j)
       next
    end if

    Mail.Send 

    if err.number = 0 then
      ' if propCorreoVerMensajes then Response.Write "Mail enviado..."
    else
      bSalida = false

      Response.Write "Envío de mail fallido. El error es " + err.description
    end if
  next
      else


  'Destinatarios con copia:
  if trim(sBCC)<>"" then

     arrayBCC = Split(sBCC,sSep)
     for i=0 to uBound(arrayBCC)
      Mail.AddBcc arrayBCC(i)
     next
  end if

    Mail.AddAddress sMailTo


on error resume next

  Mail.Send 

  if err.number = 0 then
    'if propCorreoVerMensajes then Response.Write "Mail enviado..."
  else
     bSalida = false
     Response.Write "Envío de mail fallido. El error es " + err.description
  end if
on error goto 0
end if
set Mail = nothing


    else

        ' Mensaje con encriptacion SSL o libre de ella.


        bSalida = true
        Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
        Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

        Const cdoAnonymous = 0 'Do not authenticate
        Const cdoBasic = 1 'basic (clear-text) authentication
        Const cdoNTLM = 2 'NTLM

        Set objMessage = CreateObject("CDO.Message")
        objMessage.Subject = sAsunto
        'objMessage.To = sMailTo


        if sMailFrom<>"" then

                objMessage.From  = sMailFrom
        else

                objMessage.From  = mailFrom
        end if

        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

                 'Name or IP of Remote SMTP Server
   objMessage.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailSmtp
  'Type of authentication, NONE, Basic (Base64 encoded), NTLM
   objMessage.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUser
      'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword

    'Server port (typically 25)
  objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mailPort

   'Use SSL for the connection (False or True)
  objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mailSSL

 objMessage.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 120

      objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

if instr(lcase(sCuerpo),"<html>")<>0 then 
    objMessage.HTMLBody = sCuerpo
else
    objMessage.TextBody = sCuerpo
end if

if sAdjunto<>"" then
'      arrayAdjuntos = Split(Adjunto,sSep)
'      for i=0 to uBound(arrayAdjuntos)
      objMessage.AddAttachment (sAdjunto) 'arrayAdjuntos(i)
'     next
end if

if session("idpersona")=1038 then
   if sAdjunto<>"" then Response.Write "<br>"+sAdjunto+"<br>"
end if
    arrayMailTo = Split(sMailTo,sSep)
    iNumDest = ubound(arrayMailTo)

if iNumDest < 0 then
    objMessage.To = sMailFrom
    objMessage.Send 

    if err.number = 0 then
       'if propCorreoVerMensajes then Response.Write "Mail enviado..."
    else
      bSalida = false
      Response.Write "Envío de mail fallido. El error es " + err.description + mailSmtp
    end if

elseif bPorSeparado then


  for i=0 to iNumDest
        'Para cada uno de los destinatarios en la matríz, enviamos un mensaje
   objMessage.To = arrayMailTo(i)
    'Si se envian los mails por separado, sólo se envia con copia el último, porque sino
    'a los destinatarios en sBCC les llegarían n correos repetidos:
    'Se añaden los Bcc en el último puesto que no hay posibilidad con éste objeto de borrar(clear)
    'el recipiente de Bcc.
    if i=iNumDest and trim(sBCC)<>"" then
       arrayBCC = Split(sBCC,sSep)
       for j=0 to uBound(arrayBCC)
          objMessage.BCC  = arrayBCC(j)
       next
    end if

    objMessage.Send 
    if err.number = 0 then
      ' if propCorreoVerMensajes then Response.Write "Mail enviado..."
    else
      bSalida = false
      Response.Write "Envío de mail fallido. El error es " + err.description
    end if
  next
  else

  'Destinatarios con copia:
  if trim(sBCC)<>"" then
     arrayBCC = Split(sBCC,sSep)
     for i=0 to uBound(arrayBCC)
      objMessage.BCC = arrayBCC(i)
     next
  end if 
    objMessage.To = sMailTo

on error resume next

  objMessage.Send 

  if err.number = 0 then
    'if propCorreoVerMensajes then Response.Write "Mail enviado..."
  else
     bSalida = false
     Response.Write "Envío de mail fallido. El error es " + err.description
  end if
on error goto 0
end if
set objMessage = nothing

    end if

    bCorreoEnviarGeneral = bSalida

 End Function

这篇关于TLS使用传统的ASP发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆