Solved

SMTP Script

Posted on 2007-12-03
18
5,723 Views
Last Modified: 2013-12-26
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
Comment
Question by:firza
  • 8
  • 6
  • 3
  • +1
18 Comments
 
LVL 18

Accepted Solution

by:
diasroshan earned 370 total points
ID: 20402375
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
 
LVL 14

Assisted Solution

by:sandeep_patel
sandeep_patel earned 130 total points
ID: 20403749
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
 

Author Comment

by:firza
ID: 20408277
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
 
LVL 14

Assisted Solution

by:sandeep_patel
sandeep_patel earned 130 total points
ID: 20408693
what is the return value of ConnectToNewObject call ?
0
 

Author Comment

by:firza
ID: 20408965
the return value for ConnectToNewObject = -2  ...what this number mean?
0
 
LVL 18

Assisted Solution

by:diasroshan
diasroshan earned 370 total points
ID: 20409294
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
 

Author Comment

by:firza
ID: 20409417
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
 
LVL 18

Assisted Solution

by:diasroshan
diasroshan earned 370 total points
ID: 20409517
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
 

Author Comment

by:firza
ID: 20409545
i try to find Properties in SMTP Control..but can't find...sorry cause so many question... :)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 18

Assisted Solution

by:diasroshan
diasroshan earned 370 total points
ID: 20409791
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
 

Author Comment

by:firza
ID: 20409813
Hi Rosh,

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

Assisted Solution

by:diasroshan
diasroshan earned 370 total points
ID: 20409938
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
 

Author Comment

by:firza
ID: 20409969
Hi,

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

Assisted Solution

by:diasroshan
diasroshan earned 370 total points
ID: 20417716
Hi,

Try,
o1.Object.Server =  "172.20.20.19"


Cheers,
Rosh
0
 

Author Comment

by:firza
ID: 20440390
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
 
LVL 14

Assisted Solution

by:sandeep_patel
sandeep_patel earned 130 total points
ID: 20442756
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
 

Author Comment

by:firza
ID: 20539336
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
 

Expert Comment

by:Sometex
ID: 37790118
Alternative way to send e-mail messages using SMTP server without OLE-objects:
http://dwcfilter.com
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now