Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5849
  • Last Modified:

SMTP Script

I'm using PowerBuilder to write send email script using SMTP(Outlook 2007). But, the problem is when I try to execute the script, the error like  'Error accessing external object property server' were appeared at this sintax : o1.Server = "172.20.20.19"(as code below). Anybody have any idea to solve this problem?
integer li_rtn , li_ret
string ls_attach, ls_body, ls_to 
long ll_i 
string gs_smtp_server
OLEObject o1 
int rtncode 
 
o1 = CREATE oleobject 
o1.ConnectToNewObject("SMTPControl.SMTP") 
o1.Server =  "172.20.20.19"// global string variable containing IP 
                      address
o1.port = 25 // global long with the port number - almost always 
 
 //email to
 o1.SentTo = 'emailto@mail.com.my' // email address example
 o1.CC = 'emailcc@mail.com.my'
 
 o1.MessageSubject = "New Takeover - Asset No. : "  + is_assetno 
 o1.MessageText ="Dear Sir / Madam"
                                                                         o1.SendEmail() 
 rtncode = o1.DisconnectObject() 
 
DESTROY o1

Open in new window

0
firza
Asked:
firza
  • 8
  • 6
  • 3
  • +1
9 Solutions
 
diasroshanCommented:
Hi,

first thing is that u need to have the SMTP Control installed on ur machine to successfully execute the above code snippet..

u can check the following link to send mail using SMTP, it is a question asked recently...
http://www.experts-exchange.com/Programming/Editors_IDEs/PowerBuilder/Q_22993337.html

find the code snippet also..

Cheers,
Rosh
String      ls_attach_name="c:\pdf_file.pdf"
 
mailsession lms_MAPISession
mailmessage lmm_Message
mailFileDescription mAttach
mailReturnCode lmr_ret
 
string ls_username, ls_password
lms_MAPISession = CREATE mailsession
 
IF lms_MAPISession.MailLogon() = MailReturnSuccess! THEN
      String ls_text = "Test"
      String ls_address   
      lmm_message.NoteText= message.stringparm
      lmm_Message.Subject = "test"
      
      ls_address = 'charlesaad@hotmail.com'
 
      lmm_Message.Recipient[ 1 ].address = ls_address
      lmm_Message.Recipient[ 1 ].Name = lmm_Message.Recipient[ 1 ].address 
	//	lmm_message.Recipient[ 1 ].type = smtp
      lms_MAPISession.mailAddress ( lmm_Message )
        //lms_MAPISession.mailtype = smtp
      mAttach.FileType = mailAttach!
      mAttach.PathName = ls_attach_name
      mAttach.FileName = ls_attach_name
      mAttach.Position = len(lmm_Message.notetext) - 1            
   	lmm_Message.AttachmentFile[1] = mAttach
		
      lmr_ret = lms_MAPISession.MailSend( lmm_Message ) 
      If lmr_ret = MailReturnSuccess!  Then
            Messagebox( 'Mail', 'Message  sent.' )
      Else
            Messagebox( 'Mail', 'Message  not Sent' )
      End If
    
      lms_MAPISession.MailLogoff()
END IF
 
DESTROY lms_MAPISession
 

Open in new window

0
 
sandeep_patelCommented:
Hi,
Check return value on o1.ConnectToNewObject("SMTPControl.SMTP")
li_ret = o1.ConnectToNewObject("SMTPControl.SMTP")
Messagebox('',li_ret)

It should return 0 then only rest will work..
Regards,
Sandeep
0
 
firzaAuthor Commented:
Thanks for both of you. I'm already install SMTP Control but the problem still can't solve. Did I need to setting this SMTP Control or just install it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
sandeep_patelCommented:
what is the return value of ConnectToNewObject call ?
0
 
firzaAuthor Commented:
the return value for ConnectToNewObject = -2  ...what this number mean?
0
 
diasroshanCommented:
Hi,

In PB, Goto Browser--> OLE Tab
and look for ur SMTP Control in the treeview...

once u find it, expand the Class Information... in that ull find a key called ProgID..

use this ProgID to connect to ur object...

Eg.
o1.ConnectToNewObject("<put ur ProgID here>")


If u cant find ur OLE control in the OLE tab, then ur Control is not properly installed.

Cheers,
Rosh
0
 
firzaAuthor Commented:
Now, I can connect to the object regarding on your suggestion, diasroshan....
But still error at this line :
---> o1.Server =  "172.20.20.19"
the error : R0036 : name not found accessing external object property server.
What should I do to solve this problem?
0
 
diasroshanCommented:
Hi,

Goto Browser--> OLE Tab
and look for ur SMTP Control in the treeview..

like u found Class Information, ull find Properties, Events, Functions...

Look in Properties... see if the property is 'Server' or 'Servername' or something else... use that...

Cheers,
Rosh
0
 
firzaAuthor Commented:
i try to find Properties in SMTP Control..but can't find...sorry cause so many question... :)
0
 
diasroshanCommented:
Hi,

which SMTP control are u using?

can u tell me in Browser--> OLE Tab ,under ur SMTP Control what all is there?

Cheers,
Rosh
0
 
firzaAuthor Commented:
Hi Rosh,

I have only Class Information under SMTP Control, thats all....Where can I find the information about IP for SMTP Server?
0
 
diasroshanCommented:
Hi,

which SMTP control are u using????

looks like ur control is not properly installed... else u wud have got a list of properties, events, funtions... or look further if u can see another entry for ur SMTP control...


which SMTP control are u using????


Cheers,
Rosh
0
 
firzaAuthor Commented:
Hi,

i'm using SMTP Component, download from : http://www.ostrosoft.com/download/full/smtp_component.exe ....
another SMTP Control i can download?
0
 
diasroshanCommented:
Hi,

Try,
o1.Object.Server =  "172.20.20.19"


Cheers,
Rosh
0
 
firzaAuthor Commented:
Hi...I'm sorry for late reply...
Below is the newest script i wrote...Everything look ok when I run this script....the return value of ConnectToNewObject call is 0 which mean successful connection...But when I check the email, there is no new email message in inbox...what is the next step I should do?

Thank You...
integer li_rtn 
string ls_attach, ls_body, ls_to 
long ll_i, gl_smtp_port
			
OLEObject o1 
int rtncode 
o1 = CREATE oleobject 
o1.ConnectToNewObject("OSSMTPControl.SMTP") 
li_rtn = o1.ConnectToNewObject("OSSMTPControl.SMTP") 
 
if li_rtn = 0 then
 messagebox('test connection','Successful')
end if
 
o1.SMTPServer = "xxx.xx.x.xx"  // global string variable containing IP address 
o1.port = 25 // global long with the port number - almost always 25
 
o1.MessageSubject = "New Takeover"
o1.MessageText ="Dear Sir / Madam"
o1.SendTo = "email1@email.com; email2@email.com"
o1.SendEmail() 
rtncode = o1.DisconnectObject() 
DESTROY o1

Open in new window

0
 
sandeep_patelCommented:
Hi,
Logically if you think, when you want to send email to anyone you need to login to your mail application (outlook, pegasus mail, lotus notes, etc) and then send to other.

Accordingly in your script you need userid, password (other parameters depending on your default mail application) and a funciton call which will login to your default mail application.

Check the function and property list of the object you are using in PowerBuilder object browser, definately you will find it....

Regards,
Sandeep
0
 
firzaAuthor Commented:
hi,
l already try but still nothing happen. Can any expert post to me some sample coding
on PB 10.2 that using SMTP. l need urgent.

thanks.
0
 
SometexCommented:
Alternative way to send e-mail messages using SMTP server without OLE-objects:
http://dwcfilter.com
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now