Après windows pour les nuls, voici PB pour les bons (ou presque).

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 12-04-2008 09:25:17

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

[SOURCE] PB 11.1 WEBFORM - Send PDF as Email attachment

Source : CodeXchange

Greetings All,

The following code allows a Webform user to send themself an email with the contents of a datawindow as an attachment.

Currently, PB 11.1 does not support the System.Net.Mail.AddAttachment method (until maybe PB 12). So you have to use Helper.dll that was written by Scrinivas Jonala at Sybase (Thank you Scrinivas!). 
Helper.dll and the source is available at http://65.213.119.67/helper/helper.zip

If you download this after PB 11.1 (the next release), you may need to recompile it using build.bat from the dos prompt.

Best,

Paul Murray

This is sample code and assumes that you have a webform application to publish to IIS...along with a datawindow and access to an smtp server...

Code: pb

//CODE BEGINS
mle_1.hide()
string email1
string email1flag
email1 = trim(sle_1.text)

If email1 = "" or email1 = "enter email address" then
 mle_1.text = "ERROR: YOU MUST ENTER A VALID EMAIL ADDRESS IN THE EMAIL FIELD"
 mle_1.show()
 return
end if

If email1 <> "" and email1 <> "email address1" then
 if match(email1,'^[a-zA-Z0-9][a-zA-Z\0-9\-_\.]*[^.]\@[^.][a-zA-Z\0-9\-_\.]+\.[a-zA-Z\0-9\-_\.]*[a-zA-Z\0-9]+$') then
  email1flag = 'Y'
  mle_1.text = "FIRST EMAIL IS GOOD"
 else
  mle_1.text = "THE EMAIL ADDRESS IS NOT FORMATTED CORRECTLY"
  mle_1.show()
  return
 end if
end if

//create the to address
string ToAddress2
ToAddress2 = email1

string bodytext
bodytext = 'Dear Valued Affiliate, ' + '~r~n' + '~r~n' + 'Please find attached the requested trip list in PDF format.' &
+ '~r~n' + '~r~n' + 'Thank you,' + '~r~n' + '~r~n' + 'Affiliate Operations' &
+ '~r~n' + '1-800-555-5555'

string sTripDate
sTripDate = string(today, "MM/DD/YYYY")
sTripDate = left(sTripdate,2) + "-" + mid
(sTripdate,4,2) + "-" + 
right(sTripdate,4)

//SETUP THE GHOSTSCRIPT DISTILL PROCESS
dw_1.Object.DataWindow.Export.PDF.Method=Distill!
dw_1.Object.DataWindow.Printer   =   "Sybase DataWindow PS"
dw_1.Object.DataWindow.Export.PDF.Distill.CustomPostScript="Yes"

//create the path to use LATER for the attachment
string filePathName
#if defined PBWEBFORM then
filePathName = Helper.PBInternal.ConvertVFS2ActualPath("c:\" + "Affiliate Trip Listing For-" + affiliateid + "-For-" + sTripDate + ".pdf")
#end if

//create the path and filename to use NOW to distill 
// and save the file in the virtual directory
string filename
filename = "c:\" + "Affiliate Trip Listing For-" + affiliateid + "-For-" + sTripDate + ".pdf"
dw_1.SaveAs(filename,PDF!,false)

string subject
subject = 'Affiliate Listing for ' + affiliateid + ' for Date: ' + sTripDate
string fromaddresstext
fromaddresstext = "pemurray@staysystems.com"

#if defined PBWEBFORM then
//CREATE THE MESSAGE AND ADD SUBJECT AND BODY
System.Net.mail.MailMessage message
message = create  System.Net.mail.MailMessage
message.subject = "Affiliate Listing for " + affiliateid + " for " + sTripDate
message.body = bodytext

//ADD THE FROM ADDRESS
System.Net.Mail.MailAddress fromaddress
fromaddress = create System.Net.Mail.MailAddress("pemurray@staysystems.com", "Affiliate Operations")
message.From = fromAddress

//ADD THE TO ADDRESS
System.Net.Mail.MailAddress toaddress
message.To.Add(email1);
message.Bcc.Add("pemurray@staysystems.com");

//ADD THE ATTACHMENT USING HELPER.DLL FROM SCRINIVAS
System.Net.Mail.Attachment attach
attach = create System.Net.Mail.Attachment(filePathName,"application/pdf");
Helper.Mail.AddAttachment(message, attach)

//DECLARE THE SMTP CLIENT, HOST, PORT AND SEND THE 
MESSAGE
System.Net.Mail.SmtpClient smtpclient
smtpclient = create  System.Net.Mail.SmtpClient
smtpclient.host = 'webapp.ftl.com'
smtpclient.port = 25
smtpclient.send(message)
#end if

//IF THERE IS CODE TO DESTROY THE MAIL MESSAGE AND
// SMTP CLIENT, I DON'T KNOW WHAT IT IS

mle_1.show()
mle_1.text = "Thank you.  Your listing has been emailed to the requested recipient."
//CODE ENDS 

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22