I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it. I have little experience with .NET and none using .NET Interop. I've got Visual Studio Express 14.0 and VFP 9.0 SP2 and would appreciate any pointers.
Laurie
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
This works with a legit user running it. It will need a using statement but your IDE will help you and put it in.
void sendEmail(string strFrom , string strTo , string strSubject , string strBody) {
MailMessage objMailMessage = new MailMessage(); System.Net.NetworkCredential objSMTPUserInfo = new System.Net.NetworkCredential(); SmtpClient objSmtpClient = new SmtpClient();
try { objMailMessage.From = new MailAddress(strFrom); objMailMessage.To.Add(new MailAddress(strTo)); objMailMessage.Subject = strSubject; objMailMessage.Body = strBody;
objSmtpClient = new SmtpClient("172.0.0.1"); /// Server IP objSMTPUserInfo = new System.Net.NetworkCredential ("User name", "Password","Domain"); objSmtpClient.Credentials = objSMTPUserInfo; objSmtpClient.UseDefaultCredentials = false; objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Send(objMailMessage); } catch (Exception ex) { throw ex; }
finally { objMailMessage = null; objSMTPUserInfo = null; objSmtpClient = null; } }
On Wed, Mar 30, 2016 at 6:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it. I have little experience with .NET and none using .NET Interop. I've got Visual Studio Express 14.0 and VFP 9.0 SP2 and would appreciate any pointers.
Laurie
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it.
May I ask, "Why?"
I would bet: for SSL support
Thierry Nivelet FoxInCloud Give your VFP app a second life in the cloud http://foxincloud.com/
Le 30/03/2016 13:43, Ted Roche a écrit :
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it.
May I ask, "Why?"
Hi Ted, The principal reason is that I've never got the delivery notification stuff to work in CDO.
Laurie
On 30 March 2016 at 12:54, Thierry Nivelet tnivelet@foxincloud.com wrote:
I would bet: for SSL support
Thierry Nivelet FoxInCloud Give your VFP app a second life in the cloud http://foxincloud.com/
Le 30/03/2016 13:43, Ted Roche a écrit :
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a
.NET component to do it.
May I ask, "Why?"
[excessive quoting removed by server]
Hi Stephen, Thanks for that. How do I use that class from within VFP?
Laurie
On 30 March 2016 at 13:07, Laurie Alvey trukker41@gmail.com wrote:
Hi Ted, The principal reason is that I've never got the delivery notification stuff to work in CDO.
Laurie
On 30 March 2016 at 12:54, Thierry Nivelet tnivelet@foxincloud.com wrote:
I would bet: for SSL support
Thierry Nivelet FoxInCloud Give your VFP app a second life in the cloud http://foxincloud.com/
Le 30/03/2016 13:43, Ted Roche a écrit :
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using
a .NET component to do it.
May I ask, "Why?"
[excessive quoting removed by server]
For myself I just insert rows into a sql table for outbound mail. I have a job that fires every 10 min to process any data there and I use SQL Mail as the sending process. It all works the same way in the end.
But how to call this from VFP?
Create a dll that you register in your gac. You then go through the standard steps to create an object from this dll and consume it's functionality in VFP.
On Wed, Mar 30, 2016 at 7:07 AM, Laurie Alvey trukker41@gmail.com wrote:
Hi Ted, The principal reason is that I've never got the delivery notification stuff to work in CDO.
Laurie
On 30 March 2016 at 12:54, Thierry Nivelet tnivelet@foxincloud.com wrote:
I would bet: for SSL support
Thierry Nivelet FoxInCloud Give your VFP app a second life in the cloud http://foxincloud.com/
Le 30/03/2016 13:43, Ted Roche a écrit :
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of
using a
.NET component to do it.
May I ask, "Why?"
[excessive quoting removed by server]
Thanks everyone.
Laurie
On 30 March 2016 at 13:55, Stephen Russell srussell705@gmail.com wrote:
For myself I just insert rows into a sql table for outbound mail. I have a job that fires every 10 min to process any data there and I use SQL Mail as the sending process. It all works the same way in the end.
But how to call this from VFP?
Create a dll that you register in your gac. You then go through the standard steps to create an object from this dll and consume it's functionality in VFP.
On Wed, Mar 30, 2016 at 7:07 AM, Laurie Alvey trukker41@gmail.com wrote:
Hi Ted, The principal reason is that I've never got the delivery notification
stuff
to work in CDO.
Laurie
On 30 March 2016 at 12:54, Thierry Nivelet tnivelet@foxincloud.com wrote:
I would bet: for SSL support
Thierry Nivelet FoxInCloud Give your VFP app a second life in the cloud http://foxincloud.com/
Le 30/03/2016 13:43, Ted Roche a écrit :
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of
using a
.NET component to do it.
May I ask, "Why?"
[excessive quoting removed by server]
On 2016-03-30 07:43, Ted Roche wrote:
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it.
May I ask, "Why?"
+1!!!
"If it ain't broke, ..."
On Wed, 30 Mar 2016, at 12:43 PM, Ted Roche wrote:
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it.
May I ask, "Why?"
Well, CDO is tied to Exchange Server and to my mind is gradually being deprecated.
To answer Laurie's question, I had a similar requirement recently and I achieved it by writing a .NET solution that uses the System.Net.Mail namespace and the SMTP functionality therein. It basically creates a fairly 'flat' interface, i.e.
SmtpEmailer.AddAttachment(string) SmtpEmailer.AddLinkedImage(string) SmtpEmailer.AddRecipient(string, string, string) SmtpEmailer.BuildImageTag(string, string) SmtpEmailer.Dispose() SmtpEmailer.Dispose(bool) SmtpEmailer.SendMessage() SmtpEmailer.SetBody(string) SmtpEmailer.SetBodyFormat(string) SmtpEmailer.SetCredentials(string, string, string) SmtpEmailer.SetFrom(string, string) SmtpEmailer.SetPriority(string) SmtpEmailer.SetSubject(string) SmtpEmailer.SmtpEmailer() SmtpEmailer.StartMessage() SmtpEmailer.BodyText SmtpEmailer.EnableSSL SmtpEmailer.ExceptionMessage SmtpEmailer.LastException SmtpEmailer.LastStatusCode SmtpEmailer.Port SmtpEmailer.Server SmtpEmailer.StatusCode SmtpEmailer.TimeoutSeconds SmtpEmailer.Version
This handles HTML mail with inline images (and automatically generates a text version too). Also SSL.
So that spits out a DLL, how do I use that from VFP? You could create a COM wrapper for it, but that woudl then involve building an installer and everything that entails.
What I do is use Rick Strahl's wwdotnetbridge class which allows the use of .NET assemblies directly from VFP with no installation (other than .NET 4.0 or later being present). This means 'xcopy' deployment and no messing with COM. Given the .NET DLL above and the relevant files for wwdotnetbridge in the same folder, you can just use this to send an email from VFP:
DO wwDotNetBridge LOCAL loBridge as wwDotNetBridge
loBridge = GetwwDotnetBridge() loBridge.LoadAssembly("my_dotnet_smtp.dll") && -- The .NET DLL
Local loW as my_dotnet_smtp.SmtpEmailer loW = loBridge.CreateInstance("my_dotnet_smtp.SmtpEmailer") loW.EnableSSL = .t. loW.Port = 587 loW.Server = "my.smtpserver.com" loW.SetCredentials("username", "password", "") loW.StartMessage() loW.AddRecipient("joe.bloggs@gmail.com", "Alan", "") loW.SetSubject("Here's an email.") loW.SetBodyFormat("HTML") lcLogoCID = loW.AddLinkedImage("c:\temp\logo.jpg") lcMyHTML = "<p>Title text</p>" + loW.BuildImageTag(lcLogoCID, "logo") loW.SetBody(lcMyHTML) loW.SetPriority("HIGH") loW.SetFrom("youremail@yourcompany.com", "Your Name")
try if !loW.SendMessage() ? loW.ExceptionMessage ? loW.StatusCode EndIf Catch to loException ? loW.ExceptionMessage ? loW.StatusCode Endtry loBridge.Unload() Release loBridge
+1 On 30/03/2016 17:13, Ted Roche wrote:
On Wed, Mar 30, 2016 at 7:02 AM, Laurie Alvey trukker41@gmail.com wrote:
I currently use CDO to send email from my apps but I'm thinking of using a .NET component to do it.
May I ask, "Why?"