Enviar correo con Archivo Adjunto ZIP o RAR

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.

Moderator: Flipeador

MayoMagic
Posts: 1
Joined: 06 Jun 2017, 22:38

Enviar correo con Archivo Adjunto ZIP o RAR

06 Jun 2017, 22:53

Buen dia.

Soy Nuevo en este Foro y recurro a ustedes para ver si me pueden apoyar con este código que encontré en la red, para enviar a través de Gmail, hasta el momento ya funciona el envio de correo, pero no logro hacer que se adjunte un archivo que se encuentra en c:\temp\llave.zip, el Ejecutable del Autohotkey tambien se encuentra en la misma carpeta. Espero me piedan apoyar. de antemano les agradezco.

Code: Select all

;Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus
Pmsg 						:= ComObjCreate("CDO.Message")
pmsg.From 					:= """Pionero"" <[email protected]>"
pmsg.To 					:= "[email protected]"
pmsg.BCC 					:= ""   									; Blind Carbon Copy, Invisible for all, same syntax as CC
pmsg.CC 					:= ""										; [email protected], [email protected]
pmsg.Subject 					:= "Envio Llave-123"
;pmsg.TextBody 					:= ""

pmsg.HtmlBody 					:= "<html><head><title>Hello</title></head><body><table border='1'><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table> </body></html>"

;sAttach   					:= "" 										; can add multiple attachments, the delimiter is |

fields 						:= Object()
fields.smtpserver   				:= "smtp.gmail.com" 						; specify your SMTP server
fields.smtpserverport   			:= 465 										; 25
fields.smtpusessl      				:= True 									; False
fields.sendusing     				:= 2   										; cdoSendUsingPort
fields.smtpauthenticate 			:= 1   										; cdoBasic
fields.sendusername 				:= "[email protected]"
fields.sendpassword 				:= "contraseña"
fields.smtpconnectiontimeout			:= 60
schema 						:= "http://schemas.microsoft.com/cdo/configuration/"
pfld 						:=  pmsg.Configuration.Fields

For field,value in fields
	pfld.Item(schema . field) 		:= value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
	pmsg.AddAttachment(Field)
;	pmsg.AddAttachment := sAttach
pmsg.Send()
return
Saludos
Nelson
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Enviar correo con Archivo Adjunto ZIP o RAR

07 Jun 2017, 13:40

Prueba con esta función:

Code: Select all

/*
Enviar EMAIL.
Parámetros:
	Password: la contraseña del EMAIL del remitente.
	From: el EMAIL del remitente.
	To: el EMAIL del destinatario.
	Subject: el asunto del mensaje (título).
	Body: el cuerpo del mensaje.
	Attachments: adjuntar archivos o URLs. debe espesificar un 'array'.
*/
SendEmail(Password, From, To, Subject, Body := "", Attachments := 0) {
	try {
		if (StrLen(Password) < 8 || !InStr(From, "@") || !InStr(To, "@") || (Body == "" && Subject == ""))
			Return (FALSE)
		cdomsg						:= ComObjCreate("CDO.Message")
		cdomsg.From				:= From
		cdomsg.To					:= To
		cdomsg.Subject			:= Subject
		cdomsg.TextBody		:= Body
		for Index, Attachment in Attachments
			cdomsg.AddAttachment(Attachment)
		cdoconf						:= cdomsg.Configuration.Fields
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")										:= "smtp.gmail.com"
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")									:= 465
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")										:= TRUE
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")											:= 2
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")								:= 1
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")									:= From
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")									:= Password
		cdoconf.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") 					:= 60
		cdoconf.Update(), cdomsg.Send()
	} catch
		Return (FALSE)
	Return (TRUE)
} ;https://msdn.microsoft.com/en-us/library/ms526130(v=exchg.10).aspx
Acuérdate de activar el acceso de aplicaciones menos seguras: https://www.google.com/settings/security/lesssecureapps.
for0for
Posts: 43
Joined: 03 Feb 2020, 01:52
Contact:

Re: Enviar correo con Archivo Adjunto ZIP o RAR

20 Feb 2020, 17:44

y si quiero mandar un mensaje con texto html que hago?
y por que añades todos esos links de microsoft?

Return to “Pedir Ayuda”

Who is online

Users browsing this forum: No registered users and 50 guests