Send Mails via Outlook

Discussion forum about all things Gupta, OpenText and the community.
EwaldP
Austria
Posts: 376
Joined: 07 Mar 2017, 08:00
Location: Austria

Send Mails via Outlook

Post by EwaldP » 05 Apr 2019, 09:59

Hi guys,

so far emails were sent via outlook/activex. After creating a mailitem we define from, to, subject, body, attachments etc, and display the mailitem in order to get the signature in the body (Outlook appends the signature to the body only when the mailitem is displayed) and the user have to send manually the mail (ususally he wants to complete the text)
Now we have the requirement to send multiple mails from our application without a user interaction. Instead of display the mailitem, we send the mailitem but in this case, the signature won't append. I've learned that Outlook saves the signature in the file system (C:\Users\ewald\AppData\Roaming\Microsoft\Signatures), but in Outlook you can specify different signatures for new message/reply message and html templates so it is hard to find the right signature.

Hints are very welcome

Ewald
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2912
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Send Mails via Outlook

Post by Dave Rabelink » 05 Apr 2019, 10:19

Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

renatx
Russia
Posts: 4
Joined: 12 Dec 2018, 07:39
Location: Moscow

Re: Send Mails via Outlook

Post by renatx » 05 Apr 2019, 10:31

there is a way easier to send mail using mailsend1.10.exe

EwaldP
Austria
Posts: 376
Joined: 07 Mar 2017, 08:00
Location: Austria

Re: Send Mails via Outlook

Post by EwaldP » 05 Apr 2019, 12:19

Hi Dave,

thanks for the links. I've already read the articles about GetInspector-functionality and unfortunately I had an error in my coding. Now it works.

The second approach with read the html-file works only if the user has only one email account with only one signature.

Thanks for your effort.

Ewald

Code works:
!!CB!! 129
If lv_bOk !-- Body
! // Inspector load the signature // !
If lv_bOk
Set lv_bOk = lv_oMailItem.PropGetGetInspector( lv_oSignature )
If pv_nFormatBody = olFormatHTML
! // -- read the mailbody with the signature -- // !
Set lv_bOk = lv_oMailItem.PropGetHTMLBody( lv_sSignature )
Call pv_oMail.SetBody( gfHTMLSetUmbruch( pv_oMail.GetBody( ) ) )
! // -- concatenate body + Signature
Set lv_bOk = lv_oMailItem.PropSetHTMLBody( '<br>' || pv_oMail.GetBody( ) || lv_sSignature )
Else
Set lv_bOk = lv_oMailItem.PropGetBody( lv_sSignature )
Set lv_bOk = lv_oMailItem.PropSetBody( pv_oMail.GetBody( ) || '
' || lv_sSignature )
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

EwaldP
Austria
Posts: 376
Joined: 07 Mar 2017, 08:00
Location: Austria

Re: Send Mails via Outlook

Post by EwaldP » 09 Apr 2019, 07:55

Hi guys,

one more problem. Some of the mails have to sent from another mailaccount (which is in the same outlook profile). SendUsingAccount doesn't work? Mails will be always sent from standard account.
https://docs.microsoft.com/en-us/dotnet ... ingAccount
2019-04-09 09_54_32-OpenText Gupta Team Developer 6.3 [Library] - hl_outlook.apl - [hl_outlook.apl].png
In addition, if I use the PropSetSentOnBehalfOfName ( https://docs.microsoft.com/de-de/dotnet ... halfOfName ) command, the mail will also be sent with the default account and I will immediately get back an error email that I am not authorized to send from another account.

Any hints?

Regards
Ewald
You do not have the required permissions to view the files attached to this post.
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

User avatar
H3PO4
Germany
Posts: 264
Joined: 10 Mar 2017, 07:53
Location: Rohlstorf, Germany

Re: Send Mails via Outlook

Post by H3PO4 » 24 Apr 2019, 05:55

Hi Ewald,

how many Accounts do you have in your lv_oAccounts object?

The .SetNumber to 2 is accessing the third element, isn't it?

Regards
Henning

EwaldP
Austria
Posts: 376
Joined: 07 Mar 2017, 08:00
Location: Austria

Re: Send Mails via Outlook

Post by EwaldP » 25 Apr 2019, 11:53

Hi Henning,

no, the first element is 1, the second is 2, .....

As you can see in the test example, the last account should be used, but the mail was always sent from the standard email account (which is the first one).

!!CB!! 70
Set lv_bOk = lv_oOutlook.Create( )
If lv_bOk !.. Namespace
Set lv_bOk = lv_oOutlook.GetNamespace( "MAPI", lv_oNameSpace )
If lv_bOk !-- ActiveX error OFF
Call SalActiveXAutoErrorMode( FALSE )
If lv_bOk !-- Select Mailaccount
Set lv_bOk = lv_oNameSpace.PropGetAccounts( lv_oAccounts )
If lv_bOk
Call lv_oAccounts.PropGetCount( lv_nAnz )
While lv_nAnz > 0 AND lv_nIdx <= lv_nAnz
Call lv_oVar.SetNumber( lv_nIdx, VT_I2 )
Set lv_bOk = lv_oAccounts.Item( lv_oVar, lv_oAccount )
If lv_bOk
Set lv_bOk = lv_oAccount.PropGetDisplayName( lv_sText )
Set lv_bOk = lv_oAccount.PropGetSmtpAddress( lv_sText )
Set lv_nIdx=lv_nIdx+1
If lv_bOk !-- Create MailItem
Set lv_bOk = lv_oOutlook.CreateItem( 0, lv_oMailItem )
If lv_bOk
Set lv_bOk = lv_bOk AND lv_oMailItem.PropSetTo( 'test@palmetshofer.net' )
Set lv_bOk = lv_bOk AND lv_oMailItem.PropSetSubject( gfDateToStrEx( SalDateCurrent( ), 'dd.MM.yy hh:mm' ) )
Set lv_bOk = lv_bOk AND lv_oMailItem.PropSetBodyFormat( 2 )
Set lv_bOk = lv_bOk AND lv_oMailItem.PropSetHTMLBody( 'Test' )
!
If lv_bOk !-- SendMail
Set lv_bOk = lv_bOk AND lv_oMailItem.PropSetSendUsingAccount( lv_oAccount )
! Call lv_oVar.SetBoolean( FALSE )
! Call lv_oMailItem.Display( lv_oVar )
Set lv_bOk = lv_Ok AND lv_oMailItem.Send( )
!
Call lv_oMailItem.Release( )
Call lv_oOutlook.Release( )
!
Return lv_bOk


tc006 SendMailsWithAccount.zip
You do not have the required permissions to view the files attached to this post.
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot], aspurga and 0 guests