Write the following code on say on the clicked event of a button to send
mail.
mailSession mSes
mailReturnCode mRet
mailMessage mMsg
mailFileDescription mAttach
string ls_ret, ls_syntax, ls_name,
ls_open_pathname, ls_filename
string ls_attach_name='DataWndw.psr'
int li_index, li_nret,
li_nrecipients, li_nfile
boolean lb_noerrors
/*****************************************************************
Make sure user has chosen at least one addressing option.
*****************************************************************/
//If NOT cbx_file.checked AND NOT cbx_address_live.checked Then
// MessageBox ("send Mail", &
// "Please select at least 1 address
option", &
// Exclamation!)
// wf_logoff_mail(mSes, ls_attach_name)
// return
//End If
/*****************************************************************
Obtain the syntax of the DataWindow definition and contents,
and write it in a ".dwx" transport file (in ASCII)
*****************************************************************/
dw_single.saveas(ls_attach_name,PSReport!,True)
//This is another way of sending the datawindow contents. ie breaking the
//syntax and data up and mailing them together.
//The PSR file is the prefered method now.
//is_dwsyntax = dw_1.Describe ( 'datawindow.syntax' )
//is_datasyntax = dw_1.Describe ( 'datawindow.syntax.data' )
//ls_syntax = is_dwsyntax + '~r' + is_datasyntax
//
//li_nfile = FileOpen ( ls_attach_name, StreamMode!, Write!,
LockReadWrite!, Replace! )
//If li_nfile < 0 Then
// MessageBox ( "send Mail", &
// "Unable to open file to save DataWindow
attachment", &
// StopSign! )
// wf_logoff_mail(mSes, ls_attach_name)
// return
//End If
//li_nret = FileWrite ( li_nfile, ls_syntax )
//FileClose ( li_nfile )
/*****************************************************************
Establish an instance of the Mail Session object, and log on
*****************************************************************/
mSes = create mailSession
/*****************************************************************
Note: If the mail-system user ID and password are known,
they could be hard-coded here, as shown in the
commented-out statement that follows. If user ID
and
password are not supplied, it is assumed that they
are stored in MSMAIL.INI
*****************************************************************/
mRet = mSes.mailLogon ( mailNewSession! )
//ls_ret = f_mail_error_to_string ( mRet, 'Logon:', FALSE )
//st_status_bar.text = ' Logon: ' + ls_ret
If mRet <> mailReturnSuccess! Then
MessageBox ("Mail Logon", 'Return Code <> mailReturnSuccess!' )
wf_logoff_mail(mSes, ls_attach_name)
return
End If
SetPointer(HourGlass!)
/*****************************************************************
Copy user's subject to the mail message.
Set return receipt flag If needed.
Build an Attachment structure, and assign it to the mail message.
*****************************************************************/
mMsg.Subject = "testing to send mail from Powerbuilder"
//If cbx_receipt_requested.checked Then
mMsg.ReceiptRequested = true
//End If
mMsg.notetext = "test" +"~n~r "
mAttach.FileType = mailAttach!
mAttach.PathName = ls_attach_name
mAttach.FileName = ls_attach_name
// Note: In MS Mail version 3.0b, Position=-1 puts attachment at
// the beginning of the message.
// This will place the attachment at the End of the text of the message
mAttach.Position = len(mMsg.notetext) - 1
mMsg.AttachmentFile[1] = mAttach
/*****************************************************************
If user requested "addresses-from-a-file," open that file and
read the address list.
*****************************************************************/
//If cbx_file.checked Then
// li_nret = GetFileOpenName ("Address", ls_open_pathname, &
//
ls_filename,"adr", &
// "Address Text Files (*.adr),*.adr,All Files (*.*),*.*")
// If li_nret < 1 Then return
// li_nfile = FileOpen ( ls_open_pathname )
// If li_nfile < 0 Then
// MessageBox ( "send Mail", "Unable to open file " &
// + ls_open_pathname,
StopSign! )
// wf_logoff_mail(mSes, ls_attach_name)
// return
// End If
// li_nrecipients = 0
// do while FileRead ( li_nfile, ls_name ) > 0
// li_nrecipients = li_nrecipients + 1
// mMsg.Recipient[li_nrecipients].Name = ls_name
// loop
// FileClose ( li_nfile )
//End If
/*****************************************************************
If user requested "address-from-Post-Office," call the
mail system's Address function
// *****************************************************************/
//If cbx_address_live.checked Then
// mRet = mSes.mailAddress ( mMsg )
// If mRet = mailReturnUserAbort! Then
// st_status_bar.text = "User Canceled send Mail"
// wf_logoff_mail(mSes, ls_attach_name)
// Return
// End If
// ls_ret = f_mail_error_to_string ( mRet, 'Address Mail:', FALSE )
// st_status_bar.text = ' Address Mail: ' + ls_ret
//End If
//
//
/*****************************************************************
Resolve recipient addresses, which may be only partially
supplied, to get the complete address for each one.
Loop in this until the names are all resovled with no
errors. The message will not be sent If errors are in
the user name.
The user can cancel out of resolving names which
will cancel the entire send mail process
*****************************************************************/
SetPointer(HourGlass!)
mMsg.Recipient[1].name = 'Goel,Poonam'
Do
lb_noerrors = True
li_nrecipients = UpperBound( mMsg.Recipient )
For li_index = 1 To li_nrecipients
mRet =
mSes.mailResolveRecipient(mMsg.Recipient[li_index].Name)
If mRet <> mailReturnSuccess! Then lb_noerrors = False
ls_ret = f_mail_error_to_string ( mRet, 'Resolve
Recipient:', FALSE )
MessageBox("Twist Message", "Resolve Recipient (" +
mMsg.Recipient[li_index].Name + "): " + ls_ret)
Next
If Not lb_noerrors Then
Messagebox("Microsoft Mail","Error Resolving Name(s)~n~r"+&
"The name(s) not underlined are unresolvable.~n~n~rPlease
Correct or Cancel"&
,Exclamation!)
mRet = mSes.mailAddress(mMsg)
If mRet = mailReturnUserAbort! Then
Messagebox("T...","User Canceled Send Mail")
wf_logoff_mail(mSes, ls_attach_name)
Return
End If
End If
Loop Until lb_noerrors
/*****************************************************************
Now, send the mail message, including the attachment
*****************************************************************/
If UpperBound ( mMsg.Recipient ) < 1 Then
messagebox ("Powerbuilder send","Mail must included at least 1
recipient",Exclamation!)
wf_logoff_mail(mSes, ls_attach_name)
return
End If
mRet = mSes.mailsend ( mMsg )
ls_ret = f_mail_error_to_string ( mRet, 'send Mail:', FALSE )
messagebox("pbtest", ls_ret)
//st_status_bar.text = ' send Mail: ' + ls_ret
wf_logoff_mail(mSes, ls_attach_name)
Put the above code where the mail needs to be invoked and the function
wf_logoff_mail code is as follows. This is using MAPI.
wf_logoff_mail
string ls_ret
mailreturncode mRet
/*****************************************************************
Log off from the mail system
*****************************************************************/
mRet = ams_mSes.mailLogoff ( )
ls_ret = f_mail_error_to_string ( mRet, 'Logoff:', FALSE )
//st_status_bar.text = ' Logoff: ' + ls_ret
messagebox("Twist", " Logoff: " + ls_ret)
If mRet <> mailReturnSuccess! Then
MessageBox ("Mail Logoff", 'Return Code <> mailReturnSuccess!' )
return
End If
/*****************************************************************
Finally, destroy the mail session object created earlier.
Also, delete the temporary attachment file.
*****************************************************************/
destroy ams_mses
FileDelete ( as_attach_name )
-----Original Message-----
From: Alex Sarmiento Del Carmen [SMTP:[EMAIL PROTECTED]]
Sent: Wednesday, September 13, 2000 11:52 AM
To: Pfc
Subject: PFCSIG Send e-mail with PB
Sorry, I don't speak English very well.
How do I send an e-mail (automatically) using PB?
In Spanish:
Quiero evitar que me muestre la Libreta de Direcciones
�C�mo puedo enviar un e-mail (autom�ticamente) usando PB?
Thank you
> [EMAIL PROTECTED] HOSTED BY IIGG, INC. FOR HELP WITH LIST SERVE COMMANDS, ADDRESS
> A MESSAGE TO [EMAIL PROTECTED] WITH THE FOLLOWING MESSAGE: help pfcsig
> SEND ALL OTHER INQUIRES TO [EMAIL PROTECTED]