Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending emails from VFP9 with CDO - Where’s the sent email 2

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
GB
Hi all

There are lots of examples on this forum for the above subject and I have managed to successfully implement one which sends an email seamlessly from VFP9. Perfect!

However, unlike automating an Outlook email which stores a copy in a sent folder, where (if at all) is the sent folder/place for the sent email using CDO?

Part of my app I’m putting together adds a Y to a field after the auto email process has run but if I need to refer back to the actual email sent, how would I do that or if not, any suggestions would be helpful.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Steve,

The short answer is that the sent message not saved anywhere.

Unlike Outlook, a VFP program that sends mail is not a full email client. It does not have inboxes or outboxes or any folders such as for drafts or sent messages. All that the program does is to send a message.

Essentially, it is up to you to implement your own Sent folder. How you do that depends on your needs. You could, for example, copy the email's text, and its To, From, Subject, etc, to a text file, which you would store somewhere in your file system. Or to a record in a DBF. You could then write code that lets you browse, search, etc. the sent messages, and bring selected messages to the screen.

Another option would be to send a blind copy of the message to your own email address, and then to access it through Outlook or another email client. Or, going further, you could use Outlook Automation for the whole job, rather than CDO. You could automate Outlook to send the message, in which case the message would automatically be saved in the Sent folder, which you could then access from within your program. This would also let you use Outlook's other feature, such as templates, signatures, etc. But that approach would mean you rewriting all the relevant code. And also require the users to have Outlook installed.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Actually, it depends.

That doesn't contradict Mike Lewis, but it depends what exactly you do, which version of CDO you use and what else is installed.
In context of Exchange or an own SMTP Server the mails end up in a Pickup directory. That's also at the same time the reason Mike is right. If your CDO configuration sets up the usage of an external SMTP Server, that pickup folder also exists, if at all, there and not locally.

Using CDO with an Exchange server would usually only play a role in a company that runs it as many mails are internal and then you can keep mails from employee to employee internal and confidential.

I don't know, but if you do all this for yourself, you will likely neither run your own SMTP mail server or even more specifically an Exchange server, so Mike is usually right.

If you don't work in an environment with an Exchange server you might also not want to install one, surely not with any end user, ie in a private household. Setting up your own SMTP server is not that absurd, if you do web development and already run a web server and maybe even an ftp server. An smtp server would just complete this.

Without all this background, an outbox or sent mail box or folder is not part of the mail protocol, that's only concerned with how to connect to a mail server, authenticate as valid user and send the mail(s) over. Storing the sent mail is no must for code sending mails. Notice MAPI (which defines folder objects) is not short for Mail APplication Interface, but Messaging APplication Interface. Mail standards are MIME, SMTP, IMAP and perhaps some more.

Chriss
 
Mike

The suggestion of a bcc sounds like the best and perhaps, the easiest option in my circumstances. I would then have a copy sent to my Outlook inbox. That makes sense.

Chris

Thank you for your post. I don’t run a server etc, so to keep it simple, I’ll implement a bcc of the email sent.

Appreciate the experts posts!

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
If this is about a newsletter, actually I would inverse your strategy. Make your own mail address the only TO addressee and put all newsletter receivers into BCC, so you don't send mail addresses of subscribers to other subscribers and only reveal your origin mail address, which you reveal anyway. It's good practice to use a noreply@somehere.com type of address and indicate this is an account not observed, even if sending a response to noreply does arrive.

Chriss
 
Hi Chris

This is not about newsletters etc, it’s about me sending invoices but having had much success using Outlook with VFP, the environment where my app is being used now, has Office 365 therefore, hence my reason for an alternative.

Mike Lewis posted on another thread about an API for use with 365 but that is beyond my experience.
I’m happy now, matter resolved.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Chris

Download the Desktop versions and you can automate Outlook again.

So I have called into my friends office today and he is using a desktop version of Office 365.

I currently use the below to create and send emails via Outlook:

Code:
oOutlook = Createobject('Outlook.Application')
oNameSpace = oOutlook.getnamespace('MAPI')
oOutbox = oNameSpace.GetDefaultFolder(4)
oItems = oOutbox.Items
oMailItem = oItems.Add(0)
oMailItem.To = "anemailaddress.com"
oMailItem.Subject = "The subject line"
oMailItem.HtmlBody = HtmlBody
oMailItem.attachments.add("\pdfs\"+mypdf+'.pdf')
oMailItem.ReadReceiptRequested = .T.
*oMailItem.Display
oMailItem.Send

I'll do some research now on Office 365 and post back. Is it worth me starting a new thread?

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Mike

You mentioned in this thread thread184-1808854:

Mike Lewis said:
I've now had an opportunity to test my original code using 365, and I'm pleased to report that it ran flawlessly, without any changes - as predicted by Nigel, above. (And the SMTP authentication issue doesn't seem to be a problem.)

Are you saying that you didn't have to change any coding similar to what I have posted or is there something else please?

I don't have Office 365 desktop so it's difficult to test.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Are you saying that you didn't have to change any coding similar to what I have posted

That's right. My code is a bit different from yours. But the point is that the code that worked with pre-365 Outlook works exactly the same with the desktop version of 365. At least, that was my experience. So I think it's safe to assume that you won't need to change anything in your code.

And with this code, a copy of the outgoing message should end up in the Sent folder.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Mike, very much appreciated.

I'll have to see if I can find a trial version of Office 365 just to satisfy my curiosity and confirmation.

Best wishes

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Just an update on this for anyone who may be interested or searching this forum:

I signed up for an Office 365 free month trial just to establish if the coding I posted and to confirm Mike's comments that not much was changed to allow VFP to send emails with existing codeand Chris' mention "Download the Desktop versions and you can automate Outlook again"

I am pleased to say that it worked perfctly.

Comments and posts are much appreciated.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Here a way to doo this with CDO

[pre]Local lcFileName,lcStr
Local lcPathtosave,omsg
lcPathtosave = 'c:\emails\sent\'
lcFileName = Sys(2015)+'.eml'
lcFileName=lcPathtosave+lcFileName
omsg = Createobject("CDO.Message")
omsg.To ='mike@somewhere.com'
omsg.From ='me'
omsg.subject ='test1'
omsg.htmlbody='this is a test'
omsg.Send()
lcStr = omsg.getstream
lcStr.SaveToFile(lcFileName,1)[/pre]



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top