×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Chilkat sending mail to Office 365 with attachments I'm stuck.

Chilkat sending mail to Office 365 with attachments I'm stuck.

Chilkat sending mail to Office 365 with attachments I'm stuck.

(OP)
Hi All[u],

I'm hoping someone has experience with Chilkat I'm currently just running the 30 day trial to see if it can do what I want it to.
My company is moving from a dedicated mail server on site to Office 365, a number of our current Foxpro forms automatically generate an email for our end customer using Westwind Utils and it works great but I cannot figure out how to use WW for 365 and so am trialling Chilkat.

CODE -->

LOCAL loJsonToken
LOCAL lnSuccess
LOCAL loMailman
LOCAL loEmail
LOCAL loAttach1

SET DEFAULT TO "T:\WIPTRACK\Chilkat"

* First get our previously obtained OAuth2 access token.
loJsonToken = CreateObject('Chilkat_9_5_0.JsonObject')
lnSuccess = loJsonToken.LoadFile("t:\wiptrack\chilkat\token\office365.json")

loMailman = CreateObject('Chilkat_9_5_0.MailMan')

loMailman.SmtpHost = "smtp.office365.com"
loMailman.SmtpPort = 587
loMailman.StartTLS = 1

* Use your Office365 email address for the SmtpUsername.
loMailman.SmtpUsername = "it@DOMAIN.onmicrosoft.com"
loMailman.OAuth2AccessToken = loJsonToken.StringOf("access_token")

* Create a new email object
loEmail = CreateObject('Chilkat_9_5_0.Email')

loAttach1 = CreateObject('Chilkat_9_5_0.BinData')
loAttach1.LoadFile("C:\1\c2v.txt")

loEmail.Subject = "This is sent via chilkat in vfp"
loEmail.Body = "This is a test"
loEmail.From = "IT <it@DOMAIN.onmicrosoft.com>"
lnSuccess = loEmail.AddTo("Testing email","babs23@DOMAIN.co.uk")

lnSuccess = loMailman.SendEmail(loEmail)
IF (lnSuccess <> 1) THEN
    thisform.edit1.Value= loMailman.LastErrorText &&debug purposes
    RELEASE loJsonToken
    RELEASE loMailman
    RELEASE loEmail
    CANCEL
ENDIF

lnSuccess = loMailman.CloseSmtpConnection()
IF (lnSuccess <> 1) THEN
    thisform.Label1.Caption= "Connection to SMTP server not closed cleanly."
ELSE
	thisform.Label1.Caption= "Mail Sent!"   
ENDIF

RELEASE loJsonToken
RELEASE loMailman
RELEASE loEmail 

This is the current code I am running to try and send an email with an attachment I am receiving the email just without the file attached I'm hoping someone can point me in the right direction.

Cheers,
Babs.

RE: Chilkat sending mail to Office 365 with attachments I'm stuck.

(OP)
I have managed to figure it out and will leave my solution here for anyone else that is struggling.
I hope it helps someone in the future!

CODE -->

* Create a new email object
loEmail = CreateObject('Chilkat_9_5_0.Email')

loAttach1 = CreateObject('Chilkat_9_5_0.BinData')
loAttach1.LoadFile("C:\1\c2v.txt")

loEmail.AddFileAttachment("C:\1\c2v.txt") &&Working

loEmail.Subject = "This is sent via chilkat in vfp"
loEmail.Body = "This is a test"
loEmail.From = "IT <it@DOMAIN.onmicrosoft.com>"
lnSuccess = loEmail.AddTo("Testing email","babs23@DOMAIN.co.uk") 

RE: Chilkat sending mail to Office 365 with attachments I'm stuck.

Well,

it was obvious already, just loading a file into a Chilkat_9_5_0.BinData object doesn't attach it to the mail, no matter if you name it oAttach or not. Just like creating oTextbox = CreateObject("tettbox") and wondering why no textbox appears on a form. It's just there standalone, not attached to anything.

And the mail object has an AddFileAttachment method you finally found yourself.

Chilkat also has so many code samples...
https://www.example-code.com/foxpro/email_attachme...

Always refer to all the Chilkat code samples at https://www.example-code.com/foxpro/default.asp
In your case find "Email object" on the left side, that's leading to https://www.example-code.com/foxpro/emailObj.asp
and then just search on the page, CTRL+F, and searching either "attach" or "file" leads to the code sample you need.

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close