Gambas3: Enviar un correo y ficheros adjuntos
Nos deja Shordi en el foro de gambas-es.org, la funcion que ha realizado para enviar correos electrónicos y fichereos adjuntos:
Public Function sendmail(sFrom As String, aTo As String[], sSubject As String, sBody As String, cServer As Collection, OptionalaBcc As String[], Optional aAttached As String[], Optional ldebug As Boolean) As Boolean
Dim SmtpC As New SmtpClient
Dim s, cad, fich, cmime, fname As String
SmtpC.debug = ldebug
SmtpC.host = cServer["host"]
SmtpC.user = cServer["user"]
SmtpC.password = cServer["password"]
SmtpC.Encrypt = IIf(cServer["Encrypt"], cServer["Encrypt"], Net.SSL)
SmtpC.Alternative = False
SmtpC.From = sFrom
For Each s In aTo
SmtpC.To.Add(Replace(s, " ", ""))
Next
SmtpC.Subject = sSubject
SmtpC.Body = sBody
If Not IsNull(aAttached) Then
For Each fich In aAttached
Exec ["file", "-bi", fich] To cmime
cmime = Left(cmime, InStr(cmime, ";") - 1)
fname = Right(fich, - RInStr(fich, "/"))
SmtpC.Add(File.Load(fich), cmime, fname)
Next
Endif
If Not IsNull(abcc) Then
For Each s In abcc
SmtpC.bcc.Add(s)
Next
Endif
SmtpC.send
Return True
Catch
Dim SmtpC As New SmtpClient
Dim s, cad, fich, cmime, fname As String
SmtpC.debug = ldebug
SmtpC.host = cServer["host"]
SmtpC.user = cServer["user"]
SmtpC.password = cServer["password"]
SmtpC.Encrypt = IIf(cServer["Encrypt"], cServer["Encrypt"], Net.SSL)
SmtpC.Alternative = False
SmtpC.From = sFrom
For Each s In aTo
SmtpC.To.Add(Replace(s, " ", ""))
Next
SmtpC.Subject = sSubject
SmtpC.Body = sBody
If Not IsNull(aAttached) Then
For Each fich In aAttached
Exec ["file", "-bi", fich] To cmime
cmime = Left(cmime, InStr(cmime, ";") - 1)
fname = Right(fich, - RInStr(fich, "/"))
SmtpC.Add(File.Load(fich), cmime, fname)
Next
Endif
If Not IsNull(abcc) Then
For Each s In abcc
SmtpC.bcc.Add(s)
Next
Endif
SmtpC.send
Return True
Catch
enlace al hilo de http://www.gambas-es.org con el código de la función
enlace al hilo de gambas-es org con programa
enlace al código fuente
No hay comentarios:
Publicar un comentario