PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio â†’ WINDEV 2024 â†’ How to send email with pdf attachment in Windev 12
How to send email with pdf attachment in Windev 12
Iniciado por guest, 23,mar. 2015 16:03 - 16 respuestas
Publicado el 23,marzo 2015 - 16:03
Hello All,

I have an application in Windev 12 which has been running for some time now. The client wants customer statements to be sent to each customer by email in pdf. I can generate pdf while printing but I need help how to automate the process and send each statement to the right customer (I do have all emails of customers in customer file)

What is the best method?
How to I setup SMTP?? so I can print pdf to customer email unattended.

Thanks in advance.

Sam.
Publicado el 23,marzo 2015 - 16:15
check the example WD Mailshot it's in your windev dir in \Examples\Training\WD Mailshot
Publicado el 23,marzo 2015 - 16:27
Hi Sam,

This is very simple and the help file on EmailSendMessage() might be more than enough to get you started: <a class="ExternalLink" rel="nofollow" target="_blank" href="http://doc.windev.com/en-US/?3032005">http://doc.windev.com/en-US/&hellip;</a> Just don't forget EmailCloseSession().

You can also use EmailSend() is you nedd more advanced options, but EmailSendMessage should be good enough.

Best regards,
Alexandre Leclerc
Publicado el 23,marzo 2015 - 16:34
Thanks Paulo,

I looked in the Windev 12 Directory (Windev12\Examples\Training and it does not have the mailshot example.

Sam.
Publicado el 23,marzo 2015 - 16:38
Thanks Alexandre for the response.

I did check the literature but it indicates the email.attach is ignored when you send email (it recognizes when you receive though)

Sam
Publicado el 23,marzo 2015 - 16:54
Hi Sam,

If you ar using the Email variable type ( http://doc.windev.com/en-US/… ) simply unse an EmailAttach type of variable, as described here: <a class="ExternalLink" rel="nofollow" target="_blank" href="http://doc.windev.com/en-US/?1000018752">http://doc.windev.com/en-US/&hellip;</a> (look at the first example).

You add the EmailAttach variable to the Email variable. Then send the email with EmailSendMessage() and it will work.

Best regards,
Alexandre Leclerc
Publicado el 23,marzo 2015 - 18:10
Thanks Alexandre.

I will explore it and let you know how it goes. I also realized there are some email commands introduced in later version than 12.

Best regards,

Sam
Publicado el 23,marzo 2015 - 18:22
Hi Sam,

Ok, sorry, but for version 12 you will have to use the EMail structure. No email variable available at that time. The attachments should be straightforward too because we used that a lot at that time too (I think it was an array of strings of path to the file... but this is too far in my memory). So check for the email attachment help in your version. This is working and the attachments are sent.

Best regards,
Alexandre Leclerc
Publicado el 23,marzo 2015 - 18:34
Hello All,

I do appreciate all the help so far. I noticed that most of the references given me is related to version >17.

Alternatively I wonder if the suggestion below will do the trick.

What would I need to do/setup before using ipamaterexport command so my output can go to the various emails since I can generate the pdf now by using idestination.

Thanks in advance

Sam
Publicado el 23,marzo 2015 - 18:54
This code is from version 11 so it sholud work in v12, just replace the email addresses and the information of the SMTP server and test it.

EmailStartSMTPSession("myuser","mypass","my.smtp.server")
Email.Recipient[1] = "xxx@gmail.com"
Email.NbRecipient = 1
Email.Subject = "subj"
Email.Message = "text"
Email.NbAttach=1
Email.Attach[Email.NbAttach]="c:\mydir\myfile.pdf"
Email.Sender = "my_email@gmail.com"
EmailSendMessage("myuser")
EmailCloseSession("myuser")
Publicado el 23,marzo 2015 - 19:31
Thank you Paulo.

I used the code you suggested. I added what is below to trap any errors as well.

EmailSendMessage("SessionSMTP")
IF ErrorOccurred THEN
Error(ErrorInfo(errSummary))
ELSE
Info("Email Sent")
END

//Close the SMTP session
EmailCloseSession("SessionSMTP")
.
I also ping and check for internet connected which works fine but the process just hangs without any error trapping or confirmation of execution as per above.
I send mail via gmail and yahoo and they well well.

Just wondering what else I am doing wrong.

Sam
Publicado el 23,marzo 2015 - 19:35
By the way I use smtp.gmail.com. Does anybody know of any other means to send via smtp? (virtual/dummy smtp?) just so I can test alternatives.

Thanks in advance.

Sam
Publicado el 23,marzo 2015 - 19:50
Hi Sam

if I remember correctly, v12 does NOT support sending email via a secured SMTP server, and GMAIL does not accepted NOT secured email...

So...
- either you upgrade to a newer version of windev (that would be my choice)
- or you use a SMTP server still accepting unsecured email (it is rare today)
- or you use an external tool to send the secured email (there was an example of using a .net assembly to do that available at some point, but I doubt that the support for .net assembly is going to be any better than for secured SMTP)...

Best regards
Publicado el 23,marzo 2015 - 20:22
Hi Sam,

Indeed in WD12 you will have to use the unsecured smtp server of your internet provider. (Usually they are unsecured.)

Upgrading, as Fabrice suggested, is the way to go.

Best regards,
Alexandre Leclerc
Publicado el 24,marzo 2015 - 07:08
Thank you all for the help and counsel on upgrade.

I will open a new thread to get some help deciding.

Thanks.

Sam.
Publicado el 24,marzo 2015 - 18:59
don't get me wrong, you should update your version of WINDEV but if it's only because of the SMTP server you can use several freeware server just to send emails like these ones:
http://www.softstack.com/freesmtp.html
<a class="ExternalLink" rel="nofollow" target="_blank" href="http://sourceforge.net/projects/winsmtpserver/">http://sourceforge.net/projects/winsmtpserver/</a>

If you control the mail server that will receive the messages this is a valid option, if not be careful with the blacklist and other anti-spam methods

If you are considering using gmail, hotmail and so on as smtp server check first if the limitations they have (emails per hour / day, ...) are enough for your application
Publicado el 25,marzo 2015 - 07:17
Thank you Paulo.

I will explore the suggested options. The emails are not a lot: 1200 per time per month.

Sam