none
Sending Email From VFP

    Question

  • We are using VFP 8.0 and have an outside ISP host our email.

     

    We want to use VFP to send a somewhat standardized email with a single attachment (PDF).

     

    I have tried using Blat and w3JMail (v4.4) to send email from VFP.  Both seem to give me errors in sending the mail related to not being able to contact the email server.  I have tried entering the server name using the name (i.e. smtp.myhost.net) and by IP address (reverse lookup of the name).  I can ping the server from my workstation (XP PRO).

     

    I seem to be missing something basic here, ANY suggestions would greatly be appreciated (debugging code to help troubleshoot?).

     

    Thanks

     

    Thursday, January 17, 2008 12:32 AM

Answers

  • there are multiple option to send email by using vfp

    1. using shellexecute visit

    http://www.tek-tips.com/faqs.cfm?fid=3894

     

    2.

    LOCAL loConfig AS CDO.Configuration, loFlds AS Object, loMsg AS CDO.Message

    loConfig = CREATEOBJECT("CDO.Configuration")

    loFlds = loConfig.Fields

    WITH loFlds

    *- Set the CDOSYS configuration fields to use port 25 on the SMTP server.

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

    *- Enter name or IP address of remote SMTP server.

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

    *- Assign timeout in seconds

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t.

    *- Commit changes to the object

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your user login"

    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 3

    * .item("http://schemas.microsoft.com/cdo/configuration/cdoURLProxyServer") = "smtp.mail.yahoo.com"

    .Update()

    ENDWITH

    *- Create and send the message.

    loMsg = CREATEOBJECT("CDO.Message")

    WITH loMsg

    .Configuration = loConfig

    .To = "test@test.com"

    .From = "yourlogin@gmail.com"

    .Subject = "This is a test of CDO sending e-mail"

    .HTMLBody = "This is the HTML content of the mail message"

    .AddAttachment("file with full path")

    *- Set priority to HIGH if needed

    *!* IF tlUrgent

    *!* .Fields("Priority").Value = 1 && -1=Low, 0=Normal, 1=High

    *!* .Fields.Update()

    *!* ENDIF

    TRY

    .Send()

    CATCH TO oerr

    MESSAGEBOX(oerr.message)

    ENDTRY

    ENDWITH

    Thursday, January 17, 2008 4:54 AM
  • I'm happy with Jmail.dll, the free version.

     

    You can find it here: www.dimac.net
    Go to Free Downloads and download w3Jmail

     

    The installation program extract some files, but the only necessary piece is jmail.dll.

     

    Attached the function I have wrapped around it.

     

    Jmail can manage smtp authentication, also with a complete email as user name.
    The latter is handled in a special way in my code.

     

    To use smtp authentication specify the smtp server prefaced with username and password
    in the following way:

     

    Normal smtp server: smtp.libero.it
    Auth smpt server sample 1: io_gianni:mypass@smtp.libero.it
    Auth smpt server sample 2: io_gianni@libero.it:mypass@smtp.libero.it

     

    Sample use:

    do TEST_JMAIL01
    
    do TEST_JMAIL02
    
    RETURN
    *
    PROCEDURE TEST_JMAIL01
    
    local m.server, m.subject, m.body, m.receipt_requested
    
    m.server = "smtp.libero.it"
    
    m.subject = "Test Email"
    
    m.body = "A very short body ...Smile"
    
    * if you need html email
    *m.body = filetostr("save\html email.html")
    
    m.receipt_requested = .t.
    
    local m.sender, m.address, m.attachment
    m.sender = "io_gianni@libero.it"
    m.address = "io.gianni@virgilio.it"
    m.attachment = "file01.zip"
    
    m.success = MY_JMAIL(m.server, m.sender, m.address, m.subject, m.body, m.attachment, m.receipt_requested)
    
    if m.success
    	messagebox("Email successfully sent")
    else
    	messagebox("Jmail failed to send mail")
    endif
    
    RETURN
    *
    PROCEDURE TEST_JMAIL02
    
    local m.server, m.subject, m.body, m.receipt_requested
    
    m.server = "smtp.libero.it"
    
    m.subject = "Test Email"
    
    m.body = "A very short body ...Smile"
    
    * if you need html email
    *m.body = filetostr("save\html email.html")
    
    m.receipt_requested = .t.
    
    local array a_sender[1, 2]
    
    a_sender[1, 1] = "io_gianni@libero.it"
    a_sender[1, 2] = "Gianni"
    
    local array a_address[2, 3]
    
    a_address[1, 1] = "io.gianni@virgilio.it"
    a_address[1, 2] = "Giannino Uno"
    a_address[1, 3] = "TO"
    
    a_address[2, 1] = "io_gianni@virgilio.it"
    a_address[2, 2] = "Giannino Due"
    a_address[2, 3] = "CC"
    
    local array a_attachment[2]
    
    a_attachment[1] = "FILE02.pdf"
    a_attachment[2] = "FILE03.doc"
    
    m.success = MY_JMAIL(m.server, @a_sender, @a_address, m.subject, m.body, @a_attachment, m.receipt_requested)
    
    if m.success
    	messagebox("Email successfully sent")
    else
    	messagebox("Jmail failed to send mail")
    endif
    
    RETURN
    *
    FUNCTION MY_JMAIL
    parameters m.pp_server, m.pp_sender, m.pp_address, m.pp_subject, m.pp_body, m.pp_attachment, m.pp_receipt_requested
    
    if ! file("JMAIL.DLL")
    	messagebox("JMAIL NOT installed")
    	RETURN .f.
    endif
    
    if ! empty(m.pp_server) and occurs("@", m.pp_server) > 1
    	* "io_gianni@libero.it:mypass@smtp.libero.it"
    	RETURN MY_JMAIL_AUTH()
    endif
    
    local s_MailMessage, llExecuted
    
    if type("s_MailMessage") # "O" or isnull(s_MailMessage)
    	local m.riprova, m.errore
    	m.riprova = .t.
    	m.errore = .f.
    
    	do while m.riprova
    		try
    			s_MailMessage = newobject("JMail.SMTPMail")
    			m.riprova = .f.
    		catch
    			try
    				RUN REGSVR32.EXE /s JMAIL.DLL
    			catch
    				m.riprova = .f.
    				m.errore = .t.
    			endtry
    		endtry
    	enddo
    
    	if m.errore
    		messagebox("Cannot register JMAIL.DLL")
    		RETURN .f.
    	endif
    endif
    
    with s_MailMessage
    
    	.Logging = .t.
    
    	.ISOEncodeHeaders = .f.
    
    	if ! empty(m.pp_server)
    		.ServerAddress = m.pp_server
    	endif
    
    	if type("pp_sender[1]") = "C"
    		external array pp_sender
    
    		.Sender = pp_sender[1, 1]
    		.SenderName = left(.Sender, at("@", .Sender) -1)
    		if alen(pp_sender, 2) = 2
    			.SenderName = pp_sender[1, 2]
    		endif
    	else
    		.Sender = m.pp_sender
    		.SenderName = left(.Sender, at("@", .Sender) -1)
    	endif
    
    	if ! empty(m.pp_subject)
    		.Subject = alltrim(m.pp_subject)
    	else
    		* an empty subject generate an email without the subject field
    		* and this cause OFFICE OUTLOOK to generate an error if you have asked for ReturnReceipt
    
    		.Subject = " "
    	endif
    
    	.Body = alltrim(m.pp_body)
    
    	.ReturnReceipt = m.pp_receipt_requested
    
    	if m.pp_receipt_requested
    		* added for OFFICE OUTLOOK that does not understand Return-Receipt-To
    
    		.AddNativeHeader("Disposition-Notification-To", '"' + .SenderName + '" <' + .Sender + ">")
    	endif
    
    	.AddNativeHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2670")
    	.AddNativeHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2670")
    
    	if type("pp_address[1]") = "C"
    		external array pp_address
    
    		local lnRows, lnColumns, lnIndex, lcAddress, lcDisplayName, lcType
    		lnRows = alen(pp_address, 1)
    		lnColumns = alen(pp_address, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcAddress = pp_address[lnIndex]
    			else
    				lcAddress = pp_address[lnIndex, 1]
    			endif
    			lcDisplayName = left(lcAddress, at("@", lcAddress) -1)
    			lcType = "TO"
    			if lnColumns >= 2
    				lcDisplayName = pp_address[lnIndex, 2]
    			endif
    			if lnColumns >= 3
    				lcType = pp_address[lnIndex, 3]
    			endif
    			do case
    			case lcType == "TO"
    				.AddRecipientEx(lcAddress, lcDisplayName)
    			case lcType == "CC"
    				.AddRecipientCC(lcAddress)
    			case lcType == "BCC"
    				.AddRecipientBCC(lcAddress)
    			endcase
    		endfor
    	else
    		.AddRecipientEx(m.pp_address, left(m.pp_address, at("@", m.pp_address) -1))
    	endif
    
    	if type("pp_attachment[1]") = "C"
    		external array pp_attachment
    
    		local lnRows, lnColumns, lnIndex, lcPathname, lcName
    		lnRows = alen(pp_attachment, 1)
    		lnColumns = alen(pp_attachment, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcPathname = pp_attachment[lnIndex]
    			else
    				lcPathname = pp_attachment[lnIndex, 1]
    			endif
    			lcName = justfname(lcPathname)
    			if lnColumns >= 2
    				lcName = pp_attachment[lnIndex, 2]
    			endif
    			if file(lcPathname)
    				.AddAttachment(lcPathname)
    			endif
    		endfor
    	else
    		if ! empty(m.pp_attachment) and file(m.pp_attachment)
    			.AddAttachment(m.pp_attachment)
    		endif
    	endif
    
    	.Silent = .t.
    
    	llExecuted = .Execute()
    
    	if ! llExecuted
    		local m.msg
    		m.msg = ;
    			"Email NOT sent!" + chr(13) + chr(10) + chr(13) + chr(10) + ;
    			iif(.ErrorCode # 0, ltrim(str(.ErrorCode)) + " " + .ErrorMessage + " " + .ErrorSource + "." + ;
    			chr(13) + chr(10) + chr(13) + chr(10), "") + ;
    			.Log
    		messagebox(m.msg)
    	endif
    
    	if llExecuted
    		.Close
    	endif
    endwith
    
    RETURN llExecuted
    *
    FUNCTION MY_JMAIL_AUTH
    
    local s_MailMessage, llExecuted
    
    if type("s_MailMessage") # "O" or isnull(s_MailMessage)
    	local m.riprova, m.errore
    	m.riprova = .t.
    	m.errore = .f.
    
    	do while m.riprova
    		try
    			s_MailMessage = newobject("JMail.Message")
    			m.riprova = .f.
    		catch
    			try
    				RUN REGSVR32.EXE /s JMAIL.DLL
    			catch
    				m.riprova = .f.
    				m.errore = .t.
    			endtry
    		endtry
    	enddo
    
    	if m.errore
    		messagebox("Cannot register JMAIL.DLL")
    		RETURN .f.
    	endif
    endif
    
    local m.server, m.auth_name, m.auth_pw
    m.server = m.pp_server
    m.auth_name = ""
    m.auth_pw = ""
    
    if ! empty(m.server) and occurs("@", m.server) > 1
    	* "io_gianni@libero.it:mypass@smtp.libero.it"
    	m.auth_name = left(m.server, at(":", m.server) -1)
    	m.server = substr(m.server, at(":", m.server) +1)
    	m.auth_pw = left(m.server, at("@", m.server) -1)
    	m.server = substr(m.server, at("@", m.server) +1)
    endif
    
    with s_MailMessage
    
    	.Logging = .t.
    
    	.ISOEncodeHeaders = .f.
    
    	if type("pp_sender[1]") = "C"
    		external array pp_sender
    
    		.From = pp_sender[1, 1]
    		.FromName = left(.From, at("@", .From) -1)
    		if alen(pp_sender, 2) = 2
    			.FromName = pp_sender[1, 2]
    		endif
    	else
    		.From = m.pp_sender
    		.FromName = left(.From, at("@", .From) -1)
    	endif
    
    	if ! empty(m.pp_subject)
    		.Subject = alltrim(m.pp_subject)
    	else
    		* an empty subject generate an email without the subject field
    		* and this cause OFFICE OUTLOOK to generate an error if you have asked for ReturnReceipt
    
    		.Subject = " "
    	endif
    
    	.Body = alltrim(m.pp_body)
    
    	.ReturnReceipt = m.pp_receipt_requested
    
    	if m.pp_receipt_requested
    		* added for OFFICE OUTLOOK that does not understand Return-Receipt-To
    
    		.AddNativeHeader("Disposition-Notification-To", '"' + .FromName + '" <' + .From + ">")
    	endif
    
    	.AddNativeHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2670")
    	.AddNativeHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2670")
    
    	if type("pp_address[1]") = "C"
    		external array pp_address
    
    		local lnRows, lnColumns, lnIndex, lcAddress, lcDisplayName, lcType
    		lnRows = alen(pp_address, 1)
    		lnColumns = alen(pp_address, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcAddress = pp_address[lnIndex]
    			else
    				lcAddress = pp_address[lnIndex, 1]
    			endif
    			lcDisplayName = left(lcAddress, at("@", lcAddress) -1)
    			lcType = "TO"
    			if lnColumns >= 2
    				lcDisplayName = pp_address[lnIndex, 2]
    			endif
    			if lnColumns >= 3
    				lcType = pp_address[lnIndex, 3]
    			endif
    			do case
    			case lcType == "TO"
    				.AddRecipient(lcAddress, lcDisplayName)
    			case lcType == "CC"
    				.AddRecipientCC(lcAddress)
    			case lcType == "BCC"
    				.AddRecipientBCC(lcAddress)
    			endcase
    		endfor
    	else
    		.AddRecipient(m.pp_address, left(m.pp_address, at("@", m.pp_address) -1))
    	endif
    
    	if type("pp_attachment[1]") = "C"
    		external array pp_attachment
    
    		local lnRows, lnColumns, lnIndex, lcPathname, lcName
    		lnRows = alen(pp_attachment, 1)
    		lnColumns = alen(pp_attachment, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcPathname = pp_attachment[lnIndex]
    			else
    				lcPathname = pp_attachment[lnIndex, 1]
    			endif
    			lcName = justfname(lcPathname)
    			if lnColumns >= 2
    				lcName = pp_attachment[lnIndex, 2]
    			endif
    			if file(lcPathname)
    				.AddAttachment(lcPathname)
    			endif
    		endfor
    	else
    		if ! empty(m.pp_attachment) and file(m.pp_attachment)
    			.AddAttachment(m.pp_attachment)
    		endif
    	endif
    
    	.Silent = .t.
    
    	if ! empty(m.auth_name) and ! empty(m.auth_pw)
    		.MailServerUserName = m.auth_name
    		.MailServerPassWord = m.auth_pw
    	endif
    
    	if ! empty(m.server)
    		llExecuted = .Send(m.server)
    	else
    		llExecuted = .Send()
    	endif
    
    	if ! llExecuted
    		local m.msg
    		m.msg = ;
    			"Email NOT sent!" + chr(13) + chr(10) + chr(13) + chr(10) + ;
    			iif(.ErrorCode # 0, ltrim(str(.ErrorCode)) + " " + .ErrorMessage + " " + .ErrorSource + "." + ;
    			chr(13) + chr(10) + chr(13) + chr(10), "") + ;
    			.Log
    		messagebox(m.msg)
    	endif
    
    	if llExecuted
    		.Close
    	endif
    endwith
    
    RETURN llExecuted
    *
    

    • Edited by Gianni1962 Sunday, January 10, 2016 2:56 AM
    Friday, January 18, 2008 2:12 AM
  •  Greg BC wrote:

    Correct me if I am wrong, ShellExecute uses your default email client.  I do not want to use any email client on the workstation.

     

    CDO may or may not work on XP, and the examples I've seen need an Exchange Server??  Can you send attachments using CDO?

     

    You are correct that ShellExecute uses the e-mail client on the local machine.

     

    CDO does work on XP and you do not need an Exchange Server. All you need is access to an SMTP Server either locally or on the internet. The easiest way to configure CDO is to make sure that Outlook Express is properly configured to send e-mail. You never have to use it for this purpose, but configuring it creates the registry entries necessary to configure CDO automatically.

     

    You can send attachments using CDO.

    Friday, January 18, 2008 11:52 AM

All replies

  • there are multiple option to send email by using vfp

    1. using shellexecute visit

    http://www.tek-tips.com/faqs.cfm?fid=3894

     

    2.

    LOCAL loConfig AS CDO.Configuration, loFlds AS Object, loMsg AS CDO.Message

    loConfig = CREATEOBJECT("CDO.Configuration")

    loFlds = loConfig.Fields

    WITH loFlds

    *- Set the CDOSYS configuration fields to use port 25 on the SMTP server.

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

    *- Enter name or IP address of remote SMTP server.

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

    *- Assign timeout in seconds

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t.

    *- Commit changes to the object

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your user login"

    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 3

    * .item("http://schemas.microsoft.com/cdo/configuration/cdoURLProxyServer") = "smtp.mail.yahoo.com"

    .Update()

    ENDWITH

    *- Create and send the message.

    loMsg = CREATEOBJECT("CDO.Message")

    WITH loMsg

    .Configuration = loConfig

    .To = "test@test.com"

    .From = "yourlogin@gmail.com"

    .Subject = "This is a test of CDO sending e-mail"

    .HTMLBody = "This is the HTML content of the mail message"

    .AddAttachment("file with full path")

    *- Set priority to HIGH if needed

    *!* IF tlUrgent

    *!* .Fields("Priority").Value = 1 && -1=Low, 0=Normal, 1=High

    *!* .Fields.Update()

    *!* ENDIF

    TRY

    .Send()

    CATCH TO oerr

    MESSAGEBOX(oerr.message)

    ENDTRY

    ENDWITH

    Thursday, January 17, 2008 4:54 AM
  •  Greg BC wrote:

    I have tried using Blat and w3JMail (v4.4) to send email from VFP.  Both seem to give me errors in sending the mail related to not being able to contact the email server.  I have tried entering the server name using the name (i.e. smtp.myhost.net) and by IP address (reverse lookup of the name).  I can ping the server from my workstation (XP PRO).

     

    You may find the information at these links helpful:

     

    http://fox.wikis.com/wc.dll?Wiki~SendSmtpEmail~VFP

     

    http://www.sweetpotatosoftware.com/SPSBlog/CategoryView,category,Visual+Foxpro.aspx#a6b86dea6-66ec-4f8f-a610-73dd6f896fb7

    Thursday, January 17, 2008 11:45 AM
  • I'm happy with Jmail.dll, the free version.

     

    You can find it here: www.dimac.net
    Go to Free Downloads and download w3Jmail

     

    The installation program extract some files, but the only necessary piece is jmail.dll.

     

    Attached the function I have wrapped around it.

     

    Jmail can manage smtp authentication, also with a complete email as user name.
    The latter is handled in a special way in my code.

     

    To use smtp authentication specify the smtp server prefaced with username and password
    in the following way:

     

    Normal smtp server: smtp.libero.it
    Auth smpt server sample 1: io_gianni:mypass@smtp.libero.it
    Auth smpt server sample 2: io_gianni@libero.it:mypass@smtp.libero.it

     

    Sample use:

    do TEST_JMAIL01
    
    do TEST_JMAIL02
    
    RETURN
    *
    PROCEDURE TEST_JMAIL01
    
    local m.server, m.subject, m.body, m.receipt_requested
    
    m.server = "smtp.libero.it"
    
    m.subject = "Test Email"
    
    m.body = "A very short body ...Smile"
    
    * if you need html email
    *m.body = filetostr("save\html email.html")
    
    m.receipt_requested = .t.
    
    local m.sender, m.address, m.attachment
    m.sender = "io_gianni@libero.it"
    m.address = "io.gianni@virgilio.it"
    m.attachment = "file01.zip"
    
    m.success = MY_JMAIL(m.server, m.sender, m.address, m.subject, m.body, m.attachment, m.receipt_requested)
    
    if m.success
    	messagebox("Email successfully sent")
    else
    	messagebox("Jmail failed to send mail")
    endif
    
    RETURN
    *
    PROCEDURE TEST_JMAIL02
    
    local m.server, m.subject, m.body, m.receipt_requested
    
    m.server = "smtp.libero.it"
    
    m.subject = "Test Email"
    
    m.body = "A very short body ...Smile"
    
    * if you need html email
    *m.body = filetostr("save\html email.html")
    
    m.receipt_requested = .t.
    
    local array a_sender[1, 2]
    
    a_sender[1, 1] = "io_gianni@libero.it"
    a_sender[1, 2] = "Gianni"
    
    local array a_address[2, 3]
    
    a_address[1, 1] = "io.gianni@virgilio.it"
    a_address[1, 2] = "Giannino Uno"
    a_address[1, 3] = "TO"
    
    a_address[2, 1] = "io_gianni@virgilio.it"
    a_address[2, 2] = "Giannino Due"
    a_address[2, 3] = "CC"
    
    local array a_attachment[2]
    
    a_attachment[1] = "FILE02.pdf"
    a_attachment[2] = "FILE03.doc"
    
    m.success = MY_JMAIL(m.server, @a_sender, @a_address, m.subject, m.body, @a_attachment, m.receipt_requested)
    
    if m.success
    	messagebox("Email successfully sent")
    else
    	messagebox("Jmail failed to send mail")
    endif
    
    RETURN
    *
    FUNCTION MY_JMAIL
    parameters m.pp_server, m.pp_sender, m.pp_address, m.pp_subject, m.pp_body, m.pp_attachment, m.pp_receipt_requested
    
    if ! file("JMAIL.DLL")
    	messagebox("JMAIL NOT installed")
    	RETURN .f.
    endif
    
    if ! empty(m.pp_server) and occurs("@", m.pp_server) > 1
    	* "io_gianni@libero.it:mypass@smtp.libero.it"
    	RETURN MY_JMAIL_AUTH()
    endif
    
    local s_MailMessage, llExecuted
    
    if type("s_MailMessage") # "O" or isnull(s_MailMessage)
    	local m.riprova, m.errore
    	m.riprova = .t.
    	m.errore = .f.
    
    	do while m.riprova
    		try
    			s_MailMessage = newobject("JMail.SMTPMail")
    			m.riprova = .f.
    		catch
    			try
    				RUN REGSVR32.EXE /s JMAIL.DLL
    			catch
    				m.riprova = .f.
    				m.errore = .t.
    			endtry
    		endtry
    	enddo
    
    	if m.errore
    		messagebox("Cannot register JMAIL.DLL")
    		RETURN .f.
    	endif
    endif
    
    with s_MailMessage
    
    	.Logging = .t.
    
    	.ISOEncodeHeaders = .f.
    
    	if ! empty(m.pp_server)
    		.ServerAddress = m.pp_server
    	endif
    
    	if type("pp_sender[1]") = "C"
    		external array pp_sender
    
    		.Sender = pp_sender[1, 1]
    		.SenderName = left(.Sender, at("@", .Sender) -1)
    		if alen(pp_sender, 2) = 2
    			.SenderName = pp_sender[1, 2]
    		endif
    	else
    		.Sender = m.pp_sender
    		.SenderName = left(.Sender, at("@", .Sender) -1)
    	endif
    
    	if ! empty(m.pp_subject)
    		.Subject = alltrim(m.pp_subject)
    	else
    		* an empty subject generate an email without the subject field
    		* and this cause OFFICE OUTLOOK to generate an error if you have asked for ReturnReceipt
    
    		.Subject = " "
    	endif
    
    	.Body = alltrim(m.pp_body)
    
    	.ReturnReceipt = m.pp_receipt_requested
    
    	if m.pp_receipt_requested
    		* added for OFFICE OUTLOOK that does not understand Return-Receipt-To
    
    		.AddNativeHeader("Disposition-Notification-To", '"' + .SenderName + '" <' + .Sender + ">")
    	endif
    
    	.AddNativeHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2670")
    	.AddNativeHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2670")
    
    	if type("pp_address[1]") = "C"
    		external array pp_address
    
    		local lnRows, lnColumns, lnIndex, lcAddress, lcDisplayName, lcType
    		lnRows = alen(pp_address, 1)
    		lnColumns = alen(pp_address, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcAddress = pp_address[lnIndex]
    			else
    				lcAddress = pp_address[lnIndex, 1]
    			endif
    			lcDisplayName = left(lcAddress, at("@", lcAddress) -1)
    			lcType = "TO"
    			if lnColumns >= 2
    				lcDisplayName = pp_address[lnIndex, 2]
    			endif
    			if lnColumns >= 3
    				lcType = pp_address[lnIndex, 3]
    			endif
    			do case
    			case lcType == "TO"
    				.AddRecipientEx(lcAddress, lcDisplayName)
    			case lcType == "CC"
    				.AddRecipientCC(lcAddress)
    			case lcType == "BCC"
    				.AddRecipientBCC(lcAddress)
    			endcase
    		endfor
    	else
    		.AddRecipientEx(m.pp_address, left(m.pp_address, at("@", m.pp_address) -1))
    	endif
    
    	if type("pp_attachment[1]") = "C"
    		external array pp_attachment
    
    		local lnRows, lnColumns, lnIndex, lcPathname, lcName
    		lnRows = alen(pp_attachment, 1)
    		lnColumns = alen(pp_attachment, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcPathname = pp_attachment[lnIndex]
    			else
    				lcPathname = pp_attachment[lnIndex, 1]
    			endif
    			lcName = justfname(lcPathname)
    			if lnColumns >= 2
    				lcName = pp_attachment[lnIndex, 2]
    			endif
    			if file(lcPathname)
    				.AddAttachment(lcPathname)
    			endif
    		endfor
    	else
    		if ! empty(m.pp_attachment) and file(m.pp_attachment)
    			.AddAttachment(m.pp_attachment)
    		endif
    	endif
    
    	.Silent = .t.
    
    	llExecuted = .Execute()
    
    	if ! llExecuted
    		local m.msg
    		m.msg = ;
    			"Email NOT sent!" + chr(13) + chr(10) + chr(13) + chr(10) + ;
    			iif(.ErrorCode # 0, ltrim(str(.ErrorCode)) + " " + .ErrorMessage + " " + .ErrorSource + "." + ;
    			chr(13) + chr(10) + chr(13) + chr(10), "") + ;
    			.Log
    		messagebox(m.msg)
    	endif
    
    	if llExecuted
    		.Close
    	endif
    endwith
    
    RETURN llExecuted
    *
    FUNCTION MY_JMAIL_AUTH
    
    local s_MailMessage, llExecuted
    
    if type("s_MailMessage") # "O" or isnull(s_MailMessage)
    	local m.riprova, m.errore
    	m.riprova = .t.
    	m.errore = .f.
    
    	do while m.riprova
    		try
    			s_MailMessage = newobject("JMail.Message")
    			m.riprova = .f.
    		catch
    			try
    				RUN REGSVR32.EXE /s JMAIL.DLL
    			catch
    				m.riprova = .f.
    				m.errore = .t.
    			endtry
    		endtry
    	enddo
    
    	if m.errore
    		messagebox("Cannot register JMAIL.DLL")
    		RETURN .f.
    	endif
    endif
    
    local m.server, m.auth_name, m.auth_pw
    m.server = m.pp_server
    m.auth_name = ""
    m.auth_pw = ""
    
    if ! empty(m.server) and occurs("@", m.server) > 1
    	* "io_gianni@libero.it:mypass@smtp.libero.it"
    	m.auth_name = left(m.server, at(":", m.server) -1)
    	m.server = substr(m.server, at(":", m.server) +1)
    	m.auth_pw = left(m.server, at("@", m.server) -1)
    	m.server = substr(m.server, at("@", m.server) +1)
    endif
    
    with s_MailMessage
    
    	.Logging = .t.
    
    	.ISOEncodeHeaders = .f.
    
    	if type("pp_sender[1]") = "C"
    		external array pp_sender
    
    		.From = pp_sender[1, 1]
    		.FromName = left(.From, at("@", .From) -1)
    		if alen(pp_sender, 2) = 2
    			.FromName = pp_sender[1, 2]
    		endif
    	else
    		.From = m.pp_sender
    		.FromName = left(.From, at("@", .From) -1)
    	endif
    
    	if ! empty(m.pp_subject)
    		.Subject = alltrim(m.pp_subject)
    	else
    		* an empty subject generate an email without the subject field
    		* and this cause OFFICE OUTLOOK to generate an error if you have asked for ReturnReceipt
    
    		.Subject = " "
    	endif
    
    	.Body = alltrim(m.pp_body)
    
    	.ReturnReceipt = m.pp_receipt_requested
    
    	if m.pp_receipt_requested
    		* added for OFFICE OUTLOOK that does not understand Return-Receipt-To
    
    		.AddNativeHeader("Disposition-Notification-To", '"' + .FromName + '" <' + .From + ">")
    	endif
    
    	.AddNativeHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2670")
    	.AddNativeHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2670")
    
    	if type("pp_address[1]") = "C"
    		external array pp_address
    
    		local lnRows, lnColumns, lnIndex, lcAddress, lcDisplayName, lcType
    		lnRows = alen(pp_address, 1)
    		lnColumns = alen(pp_address, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcAddress = pp_address[lnIndex]
    			else
    				lcAddress = pp_address[lnIndex, 1]
    			endif
    			lcDisplayName = left(lcAddress, at("@", lcAddress) -1)
    			lcType = "TO"
    			if lnColumns >= 2
    				lcDisplayName = pp_address[lnIndex, 2]
    			endif
    			if lnColumns >= 3
    				lcType = pp_address[lnIndex, 3]
    			endif
    			do case
    			case lcType == "TO"
    				.AddRecipient(lcAddress, lcDisplayName)
    			case lcType == "CC"
    				.AddRecipientCC(lcAddress)
    			case lcType == "BCC"
    				.AddRecipientBCC(lcAddress)
    			endcase
    		endfor
    	else
    		.AddRecipient(m.pp_address, left(m.pp_address, at("@", m.pp_address) -1))
    	endif
    
    	if type("pp_attachment[1]") = "C"
    		external array pp_attachment
    
    		local lnRows, lnColumns, lnIndex, lcPathname, lcName
    		lnRows = alen(pp_attachment, 1)
    		lnColumns = alen(pp_attachment, 2)
    
    		for lnIndex = 1 to lnRows
    			if lnColumns = 0
    				lcPathname = pp_attachment[lnIndex]
    			else
    				lcPathname = pp_attachment[lnIndex, 1]
    			endif
    			lcName = justfname(lcPathname)
    			if lnColumns >= 2
    				lcName = pp_attachment[lnIndex, 2]
    			endif
    			if file(lcPathname)
    				.AddAttachment(lcPathname)
    			endif
    		endfor
    	else
    		if ! empty(m.pp_attachment) and file(m.pp_attachment)
    			.AddAttachment(m.pp_attachment)
    		endif
    	endif
    
    	.Silent = .t.
    
    	if ! empty(m.auth_name) and ! empty(m.auth_pw)
    		.MailServerUserName = m.auth_name
    		.MailServerPassWord = m.auth_pw
    	endif
    
    	if ! empty(m.server)
    		llExecuted = .Send(m.server)
    	else
    		llExecuted = .Send()
    	endif
    
    	if ! llExecuted
    		local m.msg
    		m.msg = ;
    			"Email NOT sent!" + chr(13) + chr(10) + chr(13) + chr(10) + ;
    			iif(.ErrorCode # 0, ltrim(str(.ErrorCode)) + " " + .ErrorMessage + " " + .ErrorSource + "." + ;
    			chr(13) + chr(10) + chr(13) + chr(10), "") + ;
    			.Log
    		messagebox(m.msg)
    	endif
    
    	if llExecuted
    		.Close
    	endif
    endwith
    
    RETURN llExecuted
    *
    

    • Edited by Gianni1962 Sunday, January 10, 2016 2:56 AM
    Friday, January 18, 2008 2:12 AM
  • Surinder

     

    Thanks for the reply.

     

    Correct me if I am wrong, ShellExecute uses your default email client.  I do not want to use any email client on the workstation.

     

    CDO may or may not work on XP, and the examples I've seen need an Exchange Server??  Can you send attachments using CDO?

     

    When I tried you example code the .Update failed.

    Friday, January 18, 2008 2:17 AM
  •  Greg BC wrote:

    Correct me if I am wrong, ShellExecute uses your default email client.  I do not want to use any email client on the workstation.

     

    CDO may or may not work on XP, and the examples I've seen need an Exchange Server??  Can you send attachments using CDO?

     

    You are correct that ShellExecute uses the e-mail client on the local machine.

     

    CDO does work on XP and you do not need an Exchange Server. All you need is access to an SMTP Server either locally or on the internet. The easiest way to configure CDO is to make sure that Outlook Express is properly configured to send e-mail. You never have to use it for this purpose, but configuring it creates the registry entries necessary to configure CDO automatically.

     

    You can send attachments using CDO.

    Friday, January 18, 2008 11:52 AM
  • Gianni

     

    Thanks for the help, I think I'm still have problems connecting to my ISP SMTP server.  No matter how I shape the server name I get the error message:

     

    The message was undeliverable.  All servers failed to receive the message

    Number of attachments: 1

    attachments:

    {

    Encoding "C:\mytextfile.txt"

    }

    .execute

    {

    Trying server mail:MyServer.net

    MyServer.net failed with the message: "WSAGetLastError() returned 10053, Software caused connection abort"

    No socket for server.ConnectToServer()

    1 of 1 servers failed.

    }

     

    Any ideas?

     

    Thanks

     

    Saturday, January 19, 2008 12:26 AM
  • I discovered my problem, my antivirus was blocking it.  NOW IT WORKS!!!

     

    Thanks again.

     

     

    Saturday, January 19, 2008 1:12 AM
  • hi, i just tried you code and am getting this msg

    "must be a variable or array"

    Wednesday, August 25, 2010 6:19 PM