March 28, 2024, 03:48:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Sending Email

Started by ckoehn, July 28, 2011, 05:43:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

I did a search and looked at emailer.inc but I can't seem to get anything to work.  Is there a simple way to do this in IWBasic?

Thanks,
Clint

ckoehn

This is how it is done in vb. Can it be converted?

Public Sub SendEmail(sSMTPHost As String, sFromEmail As String, sToEmail As String, sMsg As String)
    On Error Resume Next
    Dim objMessage
    Dim fn As Integer
   
    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
   
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
   
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Integrator Monitoring Alert"
    objMessage.From = sFromEmail
    objMessage.To = sToEmail
    objMessage.TextBody = sMsg
   
    '==This section provides the configuration information for the remote SMTP server.
   
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
   
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPHost
   
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
   
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = gsUserName
   
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = gsPassword
   
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
   
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
   
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Val(gsSMTPPort)
   
    objMessage.Configuration.Fields.Update
   
    '==End remote SMTP server configuration section==

    objMessage.Send
   
    Set objMessage = Nothing
   
    On Error GoTo 0
       
End Sub



Later,
Clint

LarryMc

Quote from: ckoehn on July 29, 2011, 06:15:07 PM
Can it be converted?
Yes...
Can I help you do it? Nope, not smart enough.  Sorry


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

This one should be working - update initialization data, compile for console.
typedef BOOL int
' from CDOSysStr.inc
$define cdoSendUsingMethod L"http://schemas.microsoft.com/cdo/configuration/sendusing"
$define cdoSMTPServer L"http://schemas.microsoft.com/cdo/configuration/smtpserver"
$define cdoSMTPAuthenticate L"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
$define cdoSendUserName L"http://schemas.microsoft.com/cdo/configuration/sendusername"
$define cdoSendPassword L"http://schemas.microsoft.com/cdo/configuration/sendpassword"
$define cdoSMTPUseSSL L"http://schemas.microsoft.com/cdo/configuration/smtpusessl"
$define cdoSMTPConnectionTimeout L"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
$define cdoSMTPServerPort L"http://schemas.microsoft.com/cdo/configuration/smtpserverport"

' from cdoex.inc
enum CdoProtocolsAuthentication
cdoAnonymous =0
cdoBasic
cdoNTLM
endenum

enum CdoSendUsing
cdoSendUsingPickup =1
cdoSendUsingPort
endenum

' note: for smtp.mail.yahoo.com, change SSL property to FALSE
SendEmail(_
/* server */"smtp.mail.yahoo.com",_
/* port   */25, _
/* ssl    */FALSE, _
/* auth   */cdoBasic, _
/* from   */"from@yahoo.com", _
/* to     */"to@yahoo.com", _
/* subject*/"this is a test", _
/* message*/"my message for you", _
/* login  */"login", _
/* passwrd*/"password")


Sub SendEmail(string szServer, int nPort, BOOL bSSL, CdoProtocolsAuthentication auth, _
string szFrom, string szTo, string szSubject, string szMessage, string szLogin, string szPassword)

IDispatch objMessage, Fields

objMessage = CreateComObject("CDO.Message")
if (!objMessage)
print " CreateComObject failed"
return
endif

Check(SetComProperty(objMessage, "Subject=%s", szSubject), "Subject")
Check(SetComProperty(objMessage, "From=%s", szFrom), "From")
Check(SetComProperty(objMessage, "To=%s", szTo), "To")
Check(SetComProperty(objMessage, "TextBody=%s", szMessage), "TextBody")

'==This section provides the configuration information for the remote SMTP server.
Fields = objMessage.Configuration.Fields
if (!Fields)
print "error in objMessage.Configuration.Fields"
else
Check(SetComProperty(Fields, "Item(%S)=%d", cdoSendUsingMethod, cdoSendUsingPort), "cdoSendUsingMethod")

'Name or IP of Remote SMTP Server
Check(SetComProperty(Fields, "Item(%S)=%s", cdoSMTPServer, szServer), "cdoSMTPServer")

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
Check(SetComProperty(Fields, "Item(%S)=%d", cdoSMTPAuthenticate, auth), "cdoSMTPAuthenticate")

'Your UserID on the SMTP server
Check(SetComProperty(Fields, "Item(%S)=%s", cdoSendUserName, szLogin), "cdoSendUserName")

'Your password on the SMTP server
Check(SetComProperty(Fields, "Item(%S)=%s", cdoSendPassword, szPassword), "cdoSendPassword")

'Use SSL for the connection (False or True)
Check(SetComProperty(Fields, "Item(%S)=%b", cdoSMTPUseSSL, bSSL), "cdoSMTPUseSSL")

'Connection Timeout in seconds (the maximum time CDO will try to establish
'a connection to the SMTP server)
Check(SetComProperty(Fields, "Item(%S)=%d", cdoSMTPConnectionTimeout, 10), "cdoSMTPConnectionTimeout")

'Server port (typically 25)
Check(SetComProperty(Fields, "Item(%S)=%d", cdoSMTPServerPort, nPort), "cdoSMTPServerPort")

Check(CallObjectMethod(Fields, "Update()"), "Update")
Fields->Release()
endif
'==End remote SMTP server configuration section==

Check(CallObjectMethod(objMessage, "Send()"), "Send")
objMessage->Release()
EndSub


sub Check(uint hr, string hint,opt int lineno=__LINE__)
if (hr&0x80000000)
print "Failure in line ", lineno," - ", hint
endif
endsub

ckoehn

Thanks sapero,

Will give it a try.

Later,
Clint

Bruce Peaslee

If you just want to send a message from your default email program you can use:

ShellExecuteA(0,"open","mailto:" + sEmailAddress, 0, 0, 1)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles