使用经典ASP的Tls发送邮件

Tls using classic asp to send mail

是否有可能使用TLS使用免费的库通过ASP Classic发送邮件?

我使用过CDO,但我认为不允许TLS。

谢谢大家,对不起这个问题。 我可以毫无问题地使用Gmail发送邮件,但是现在我需要使用仅允许Tls身份验证的服务器发送邮件。 我在api或Internet中找不到使用TLS发送邮件的方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    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""+sAdjunto+""
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


无需外部库。

更改

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

1
2
3
'Use TLS for the connection (False or True)
 objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendtls") = mailSSL


使用此代码,您可以使用SSL,TLS发送,不使用它们,附加一个文件,发送到多个地址,不使用BCC发送.....唯一的问题是您需要使用ASPemail pay lib。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
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""+sAdjunto+""
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""+sAdjunto+""
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