' Il seguente frammento di codice mostra come creare un messaggio e-mail con allegato un PDF generato dalla stampa di un report generato a partire dai dati del form corrente
' Il messaggio viene visualizzato e deve essere inviato dall'utente
dim CODDOC as string = form.form_state.dmd_ref.DOCUMENT.rowset.fields("_CODDOC").value
dim ADEST as dbarray = new dbarray()
dim cod_forn = form.findcontrol("Notebook1").controls(1).findcontrol("Fornitore1").findcontrol("FornitoreCodice1").value
if empty (cod_forn)
form.alert("Please, fill in the supplier")
else
' Creo il PDF del report OrderReport.repx
Dim f as string
Dim par as new Assocarray()
par("NUMDOC") = CODDOC
f = PrintReportWeb(form.Session, "OrderReport.repx", New DBArray, nothing, New DBArray, par, "PDF") ' !!! ATTENZIONE: la chiamata a PrintReportWeb non va MAI inserita all'interno di una transazione
' MAIL - ADEST - Recupero l'email del fornitore a cui inviare l'ordine
dim email_forn as qwtable = new qwtable
dim err as string
par("CODFOR") = cod_forn
email_forn = OpenTable(form, "select email from CLIFOR where CODICE = :CODFOR", par, false, false, err)
if empty(err)
if email_forn.rowset.first()
ADEST.add(email_forn.rowset.fields(1).value)
end if
CloseTable(form, email_forn)
else
form.Alert(err, "ERRORE")
end if
' MAIL - Costruzione dell'oggetto della mail
dim TIPO_CONT as string = form.findcontrol("TIPO_CONT").Value
dim NUMERO as string = form.findcontrol("NUMERO").value
dim oggetto_mail as string = "SOMFY ESPANA - Order n. " + TIPO_CONT + "/" + NUMERO
' MAIL - Costruzione del corpo della mail
dim corpo_mail as string
corpo_mail = "Dear supplier, " + "
" + _
" We would like to place the order contained in the attached file." + "
" + _
"Please confirm receipt of this order." + "
" + _
"
" + _
"Yours faithfully," + "
"
' MAIL - Costruzione della mail con i campi calcolati in precedenza
Dim qmail as QWMail = New QWMail
qmail.MsgCreate()
qmail.MsgFrom("[email protected]")
qmail.MsgAddDest(adest(1),1)
qmail.MsgSubject(oggetto_mail)
qmail.MsgText(corpo_mail)
qmail.MsgAttachment(oggetto_mail + ".PDF", Q95_PATH_TEMP + "\" + f)
qmail.MsgShow(form)
end if