Re: sending mail through Office365 using SMTP

2018-11-20 Thread Chris Belanger via 4D_Tech
The solution for sending email through Office 365 (as it worked for me).
You would need to adjust according to taste. Hopefully enough detail is 
provided to make it helpful.
— Chris Belanger


INTERPROCESS VARS:   
<>eHOST   — in this instance, is smtp.office365.com
 <>eFROM  — default email address of sender (can be over-ridden by caller)
 <>CR [char(13)],   
<>CurrentUserName  [name of the user; for reminding them they must give the 
needed fields as per the ALERT( ) ]
  
<>Auth_UN [email address]   
<>Auth_PW [email account password]

  //eMAIL_SEND_OFFICE_365(Host;From;To;CC;BCC;Subject;Body;Attachments)
C_TEXT($1;$2;$3;$4;$5;$6;$7;$8)  // the items that make up the email
  // we set up the following vars to clarify what is happening
C_TEXT($Host;$From;$To;$CC;$BCC;$Subject;$Body;$Attachments)

$Host:=$1
If ($Host="")
$Host:=<>eHOST
End if 
$From:=$2
If ($From="")
$From:=<>eFROM
End if 
If (($Host="") | ($From=""))  // watch for situations where an eMail is going 
to be sent for which we are lacking a HOST or FROM
ALERT("You must enter the eMail HOST & FROM fields in the USERS record 
for "+<>CurrentUserName+" before you can send eMails.")
Else 
$To:=$3
$CC:=$4
$BCC:=$5
$Subject:=$6
$Body:=$7+<>CR
$Attachments:=$8
C_BOOLEAN(<>ShowErrors)
<>ShowErrors:=True

C_LONGINT(SMTP_ID)
C_BOOLEAN($SentOK;$OK)

$SentOK:=False
$err:=IT_SetPort (2;587)
$wdw:=Open window(50;300;300;400;Modal dialog box)
STATUS_LINE (2;"Sending email...please wait")

Case of 

: (Not(eMail_ERRCHECK ("SMTP_New";SMTP_New (SMTP_ID
: (Not(eMail_ERRCHECK ("SMTP_Host";SMTP_Host 
(SMTP_ID;$Host;0
: (Not(eMail_ERRCHECK ("SMTP_From";SMTP_From 
(SMTP_ID;$From;1
: (Not(eMail_ERRCHECK ("SMTP_ReplyTo";SMTP_ReplyTo 
(SMTP_ID;$From;0
: (Not(eMail_ERRCHECK ("SMTP_To";SMTP_To (SMTP_ID;$To;0
: (Not(eMail_ERRCHECK ("SMTP_Cc";SMTP_Cc (SMTP_ID;$CC;0
: (Not(eMail_ERRCHECK ("SMTP_Bcc";SMTP_Bcc (SMTP_ID;$BCC;0
: (Not(eMail_ERRCHECK ("SMTP_Subject";SMTP_Subject 
(SMTP_ID;$Subject;0
: (Not(eMail_ERRCHECK ("SMTP_Body";SMTP_Body 
(SMTP_ID;$Body;0
: (Not(eMail_ERRCHECK ("SMTP_Attachment";SMTP_Attachment_It 
(SMTP_ID;$Attachments;2;0
: (Not(eMail_ERRCHECK ("SMTP_Auth";SMTP_Auth 
(SMTP_ID;<>Auth_UN;<>Auth_PW
: (Not(eMail_ERRCHECK ("SMTP_Send";SMTP_Send (SMTP_ID;0
: (Not(eMail_ERRCHECK ("SMTP_Clear";SMTP_Clear (SMTP_ID

End case 
CLOSE WINDOW($wdw)

End if 


——
  // STATUS_LINE(Line#;Msg) -- put this message on prescribed line.
C_LONGINT($1)
C_TEXT($2)

GOTO XY(2;$1)
MESSAGE($2+(" "*40))

——


  // eMail_ERRCHECK() -- used inside of our email-sender routine.
C_TEXT(vErrorMsg)
$Command:=$1
$Error:=$2
$Result:=True
If ($Error#0)
$Result:=False
If (<>SHOWERRORS)  //Boolean to determine whether to display error 
messages
vErrorMsg:=IT_ErrorText ($Error)
ALERT("ERROR ---"+Char(13)+"Command: "+$Command+Char(13)+"Error 
Code"+String($Error)+Char(13)+"Description"+vErrorMsg)
End if 
End if 
$0:=$Result

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: sending mail through Office365 using SMTP

2018-11-20 Thread Chris Belanger via 4D_Tech
thanks, Spencer.

I neglected to include that in the sample code. Above it is the line:

$error:=IT_SetPort (2;587)  


> On Nov 20, 2018, at 4:15 PM, Spencer Hinsdale via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> in the docs for Send there is an Exchange example that set Port
> 587. 
> Spencer
> 
> 
>> On Nov 20, 2018, at 2:58 PM, Chris Belanger via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> Hi,
>> 
>> I have a client that has switched its email provider to use Office365.
>> My app sends emails using SMTP_Send( ) perfectly well with other providers, 
>> but not Office365.
>> 
>> Any help you may offer will be appreciated.
>> 
>> 
>> my significant part of my code currently is:
>> [edited to include the IT_SetPort() call]

$error:=IT_SetPort (2;587)  

>> Case of
>> 
>>   : (Not(eMail_ERRCHECK ("SMTP_New";SMTP_New (SMTP_ID
>>   : (Not(eMail_ERRCHECK ("SMTP_Host";SMTP_Host (SMTP_ID;$Host;0
>>   : (Not(eMail_ERRCHECK ("SMTP_From";SMTP_From (SMTP_ID;$From;1
>>   : (Not(eMail_ERRCHECK ("SMTP_ReplyTo";SMTP_ReplyTo (SMTP_ID;$From;0
>>   : (Not(eMail_ERRCHECK ("SMTP_To";SMTP_To (SMTP_ID;$To;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Cc";SMTP_Cc (SMTP_ID;$CC;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Bcc";SMTP_Bcc (SMTP_ID;$BCC;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Subject";SMTP_Subject 
>> (SMTP_ID;$Subject;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Body";SMTP_Body (SMTP_ID;$Body;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Attachment";SMTP_Attachment_It 
>> (SMTP_ID;$Attachments;2;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Auth";SMTP_Auth 
>> (SMTP_ID;True;<>Auth_UN;<>Auth_PW
>>   : (Not(eMail_ERRCHECK ("SMTP_Send";SMTP_Send (SMTP_ID;0
>>   : (Not(eMail_ERRCHECK ("SMTP_Clear";SMTP_Clear (SMTP_ID
>> Else 
>>$SentOK:=True
>> End case 
>> 
>> SMTP_Auth( ) works without error, but then
>> SMTP_Send( ) returns error:   10032 ‘Unknown or invalid response’
>> 
>> Thanks for any help,
>> 
>> Chris Belanger
>> Innovative Solutions

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: sending mail through Office365 using SMTP

2018-11-20 Thread Spencer Hinsdale via 4D_Tech
in the docs for Send there is an Exchange example that set Port
587. 
Spencer


> On Nov 20, 2018, at 2:58 PM, Chris Belanger via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> Hi,
> 
> I have a client that has switched its email provider to use Office365.
> My app sends emails using SMTP_Send( ) perfectly well with other providers, 
> but not Office365.
> 
> Any help you may offer will be appreciated.
> 
> 
> my significant part of my code currently is:
> 
> Case of
> 
>: (Not(eMail_ERRCHECK ("SMTP_New";SMTP_New (SMTP_ID
>: (Not(eMail_ERRCHECK ("SMTP_Host";SMTP_Host (SMTP_ID;$Host;0
>: (Not(eMail_ERRCHECK ("SMTP_From";SMTP_From (SMTP_ID;$From;1
>: (Not(eMail_ERRCHECK ("SMTP_ReplyTo";SMTP_ReplyTo (SMTP_ID;$From;0
>: (Not(eMail_ERRCHECK ("SMTP_To";SMTP_To (SMTP_ID;$To;0
>: (Not(eMail_ERRCHECK ("SMTP_Cc";SMTP_Cc (SMTP_ID;$CC;0
>: (Not(eMail_ERRCHECK ("SMTP_Bcc";SMTP_Bcc (SMTP_ID;$BCC;0
>: (Not(eMail_ERRCHECK ("SMTP_Subject";SMTP_Subject 
> (SMTP_ID;$Subject;0
>: (Not(eMail_ERRCHECK ("SMTP_Body";SMTP_Body (SMTP_ID;$Body;0
>: (Not(eMail_ERRCHECK ("SMTP_Attachment";SMTP_Attachment_It 
> (SMTP_ID;$Attachments;2;0
>: (Not(eMail_ERRCHECK ("SMTP_Auth";SMTP_Auth 
> (SMTP_ID;True;<>Auth_UN;<>Auth_PW
>: (Not(eMail_ERRCHECK ("SMTP_Send";SMTP_Send (SMTP_ID;0
>: (Not(eMail_ERRCHECK ("SMTP_Clear";SMTP_Clear (SMTP_ID
> Else 
> $SentOK:=True
> End case 
> 
> SMTP_Auth( ) works without error, but then
> SMTP_Send( ) returns error:   10032 ‘Unknown or invalid response’
> 
> Thanks for any help,
> 
> Chris Belanger
> Innovative Solutions
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**