Future of email sending from Windows desktop application - email

Sergey CDO class
https://www.berezniker.com/content/pages/visual-foxpro/cdo-2000-class-sending-emails
is used to send emails.
CDO is no longer supprted:
https://support.microsoft.com/en-us/topic/collaboration-data-objects-cdo-1-2-1-is-not-supported-with-outlook-2010-and-later-versions-268ce809-7923-95ba-2c70-3f23569f57eb
How to send e-mails from Visual FoxPro 9 Desktop application using supported method ?

If you're using CDO then you're sending via Outlook, so why not just automate Outlook directly ?
loOutlook = CreateObject("Outlook.Application")
loMessage = loOutlook.CreateItem(0)
loMessage.Subject = "test email 1"
loMessage.Recipients.Add("recipient#company.com")
loMessage.BodyFormat = 2 && 2 = html 3 = rtf
lcHtmlBody = "<html><body>This is the body text.</body></html>"
loMessage.HTMLBody = lcHtmlbody
loMessage.Send()

Related

Check if CDO e-mail is supported on Volusion Windows server

I am trying to use CDO to send e-mail through a Volusion Windows server. The ASP script I've written works fine on a GoDaddy Windows server so I know the script is correct but it doesn't work through Volusion. In that script, I had used GoDaddy's relay-hosting.secureserver.net SMTP server to send the e-mail and it worked great on the GoDaddy server but not on Volusion.
I've tried several SMTP servers. Volusion provides documentation on their mail servers here:
https://support.volusion.com/article/connecting-my-volusion-e-mail-account
I've tried both the SMTP servers with SSL and without in the script (and have also tried all the different ports).
I'm wondering if the ability to send e-mails with CDO is not supported on Volusion servers? Is there a way to check if a server supports CDO without having access to the cPanel, WHM or any core files? With Volusion, they only give you access to part of the FTP.
Thanks for your help!
EDIT
Here is the code I used that worked:
<%
sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"
' Set the mail server configuration
Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
' Server port (typically 25)
objConfig.Fields.Update
' Create and send the mail
Set myMail=CreateObject("CDO.Message")
' Use the config object created above
Set myMail.Configuration=objConfig
myMail.From="test#test.com"
myMail.To="test#test.com"
myMail.Subject = "Test Subject"
myMail.HTMLBody = "Test"
myMail.Send
Set myMail = Nothing
response.write "Success!!"
%>
I've obviously updated those e-mail address when I run the code.
EDIT
To answer a question in the comments my server version is:
Microsoft-IIS/6.0
To answer your initial question, how to check CDO is supported.
Here is a quick example of checking for the Object Required error (or any error for that matter while instantiating the CDO COM object.
Dim cdo, is_cdosupported
On Error Resume Next
Err.Clear
Set cdo = Server.CreateObject("CDO.Configuration")
is_cdosupported = (Err.Number <> 0)
On Error Goto 0
If is_cdosupported Then
Call Response.Write("CDO is supported")
Else
Call Response.Write("CDO not supported")
End If
Digging around on Google
After commenting a few times decided to dig into Volusion (must admit not one I've come across and after a quick search in Google found this link.
Quote from The VSMTP Key
A special ASP class is provided for use with Volusion's built-in send-mail component, VSMTP.
You can use this class to create your own send mail solutions for your store using ASP. Note that the information being provided in this article is intended for advanced users. This solution provides an alternate to sending email via Volusion's standard POP-based or webmail-based solutions.
If you're using Volusion's standard email hosting resources (POP, IMAP, or Webmail), you will not be required to update any functions within your store or my.volusion.com account.
To use the VSMTP component with your Volusion store, you will need to download Volusion's VSMTP ASP class.
Judging by the Object Required ASP component error you get when trying to instantiate the CDO components I would say that CDO is not supported by Volusion servers.
There is a simple example shown using the VSMTP ASP class
<%
Dim mailer
Set mailer = new vsmtp
mailer.VsmtpKey = "65539C7A-525C-4CB7-B36B-BFBBDD332DD6"
mailer.EmailSubject = "Test Subject"
mailer.EmailFrom = "test#testdomain.com"
mailer.EmailTo = "test#testdomain.com"
mailer.TextBody = "Hello World!"
mailer.HTMLBody = "Hello World"
mailer.AddAttachment Server.MapPath("/v/test1.txt")
mailer.AddAttachment "/v/test2.txt"
mailer.Send()
%>
Your best bet is to adapt your existing script to use this VSMTP bespoke class that is support by Volusion.
Looking at the VSMTP ASP class, it looks like it's a simple wrapper to POST to an ASP endpoint (vsmtp.asp).
<%
Class vsmtp
Public VsmtpKey
Public EmailSubject
Public EmailFrom
Public EmailTo
Public TextBody
Public HTMLBody
Private Attachment
Private AttachmentFolder
Public Sub AddAttachment(ByRef FilePath)
If AttachmentFolder = "" Then
AttachmentFolder = Server.MapPath("/v")
End If
If StrComp(Left(FilePath,Len(AttachmentFolder)),AttachmentFolder,vbTextCompare) = 0 Then
FilePath = Replace(Mid(FilePath,Len(AttachmentFolder)-1),"\","/")
End If
If StrComp(Left(FilePath,3),"/v/",vbTextCompare) <> 0 Or InStr(FilePath,",") > 0 Then
Err.Raise 512, "vsmtp.AddAttachment", "Invalid Attachment Path"
End If
If IsEmpty(Attachment) Then
Attachment = FilePath
Else
Attachment = Attachment & "," & FilePath
End If
End Sub
Public Sub Send()
Dim HTTPRequest
Set HTTPRequest = CreateObject("WinHTTP.WinHTTPRequest.5.1")
HTTPRequest.Open "POST", "http://" & Request.ServerVariables("LOCAL_ADDR") & "/vsmtp.asp", False
HTTPRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTPRequest.SetRequestHeader "Host", Request.ServerVariables("SERVER_NAME")
HTTPRequest.Send _
"VsmtpKey=" & Server.URLEncode(VsmtpKey) &_
"&Subject=" & Server.URLEncode(EmailSubject) &_
"&FromEmailAddress=" & Server.URLEncode(EmailFrom) &_
"&ToEmailAddress=" & Server.URLEncode(EmailTo) &_
"&Body_HTML=" & Server.URLEncode(HTMLBody) &_
"&Body_TextOnly=" & Server.URLEncode(TextBody) &_
"&Attachment_CSV=" & Server.URLEncode(Attachment)
If HTTPRequest.ResponseText <> "True" Then
Set HTTPRequest = Nothing
Err.Raise 8, "vsmtp.Send", "Unable to send email. Check logs for details."
End If
Set HTTPRequest = Nothing
End Sub
End Class
%>
Short answer, you cannot. You will get an error message that states Access is denied. VSMTP is the only alternative to sending email directly from Volusion, however, you can only send from their SMTP servers and the options (e.g. Headers) are limited to what is provided.

Microsoft.Exchange.WebServices.Data.ServiceResponseException: When Sending Emails

I am using EWS Managed API to send email.
I am getting a Microsoft.Exchange.WebServices.Data.ServiceResponseException: EmailAddress or ItemId must be included in the request.
In the Soap return XML I see ErrorMissingInformationEmailAddress : This error occurs if the EmailAddress (NonEmptyStringType) element is missing.
Which email address is it talking about?
Using Exchange 2007 SP1.
Exchange credentials are correct and the to/from email addresses are valid emails.
Any ideas? Google has not helped.
Same code has worked for other Exchange Servers.
service.AutodiscoverUrl() does not work for this server.
using Microsoft.Exchange.WebServices.Data;
protected void SendEwsMail()
{
//Trust all certificates
System.Net.ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential("user#domain.com", "password");
service.Url = new Uri("Url");
var email = new EmailMessage(service);
email.ToRecipients.Add("user#domain.com");
email.From = new EmailAddress("user#domain.com");
//email.ReplyTo.Add(recipient.FromAddress);
email.Sender = new EmailAddress("user#domain.com");
email.Subject = "test";
// Send the message and save a copy.
email.SendAndSaveCopy();
}
It turns out that for the mail Server (MS Exchange) in question I needed to use this method:
Writing an encrypted mail via Exchange Web Services
var item = new EmailMessage(service);
item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content);
// Set recipient infos, etc.
item.Send();
It seems to be because of the encrypyed MIME attachment. Using the standard To, From, Subject properties of the Microsoft.Exchange.WebServices.Data.EmailMessage class does not work correctly.
Although it does work as expected when the mail server was SmarterMail.
SmarterMail 9.x is one of the only mail servers (including Microsoft Exchange) to support Exchange Web Services (EWS).
(from http://blogs.smartertools.com/tag/exchange-web-services/)
Anyone know why SmarterMail would behave differently to MS Exchange?

Sent Outlook draft from other Computer

I got eMail account on Exchange Server and that situation. I start on my
Computer outlook (connected to this Email) run this code. The Email will created and saved in drafts.Thats working fine.
Than i take my notebook (connected to the same account) and try to sent it from the drafts. Get error wrong email address but it looks like correct address "test#test.com". If i delete this and type one more time the same address from my keyboard "test#test.com" it works.I got Windows 7 ,`Outlook 2013 with disabled Cached Exchange Mode.
_OutlookApplication = New Microsoft.Office.Interop.Outlook.Application
Dim mailItem = CType(_OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem)
mailItem.Recipients.Add("test#test.com")
mailItem.Body ="Text"
mailItem.Subject = "Subject"
mailItem.Save()
Why should i retype the address? and how can i fix it?
_OutlookApplication = New Microsoft.Office.Interop.Outlook.Application
Dim mailItem = CType(_OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem)
Dim _TestRec As Recipient
_TestRec=mailItem.Recipients.Add("test#test.com")
_TestRec.AddressEntry.Address = "test#test.com"
mailItem.Body ="Text"
mailItem.Subject = "Subject"
mailItem.Save()
The problem is - mailItem.to setting only the Display Name. Had only to create a Recipient and set Recipient.AddressEntry.Address mailItem.Recipients.Add("test#test.com")

Use another framework than persits for Mails

I have to move some customer website from one (old) server to another (newer one). All sites are programmed in ASP. One customer sends Email (for his webshop) to his users using the persits framework, like
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.domain.com"
Mail.CharSet = "ISO..."
Mail.Username = "Admin#domain.com"
Mail.Password = "password"
Mail.From = shopmail
Mail.FromName = "Name"
Mail.AddAddress shopmail
Mail.Subject = "Order " & date
Mail.Body = msgBody
Mail.Send
This framework isn't installed on the new server and also there are no SMTP services installed.
How could I get it done that mails could be sent without the features mentioned above? Is there a way to reach a external STMP server with ASP?
Thanks in advance.
Best regards.
I'v found a solution, it's well documented here (for everyone who's interested in :) ).

Sending email to a SAP inbox and an ordinary email inbox

I needed a function to send an email to an ordinary email address and to send on too to an SAP Inbox. I found this function:
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
The it_receivers it's filled like this:
FREE wa_it_receivers.
wa_it_receivers-receiver = sy-uname. "&----- Assign SAP User Id
wa_it_receivers-rec_type = 'B'. "&-- Send to SAP Inbox
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
This only send's the email to the SAP inbox. I went to the domain of the rec_type field to see which letter is so it can send the email to an ordinary email account. I believe it is 'A' but, as it only says external address. Is that the one? Thank you.
I don't know why people keep on digging up that old function module. I'd always recommend using the Business Communication Services API - it's well documented and much easier to use. The docs also contain an example on how to send to an external mail address.
Here you have a nice example of how to do it wiki.sdn.sap.com