What namespace do I use when sending a message with VBA and CDO for SMTP?

StackOverflow https://stackoverflow.com/questions/11568768

  •  22-06-2021
  •  | 
  •  

سؤال

I do not understand why every example I have seen has the schema from microsoft for the namespace. What is it for? Is it really sending something by looking at Microsoft servers?

How do I use CDO with Exchange with vbscript

I would post my code but it and all examples all have the same thing:

objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")= cdoSendUsingPort

I don't want to put the microsoft schema in there. I just want to send it to my Exchange or SMTP server. Thanks.

هل كانت مفيدة؟

المحلول

The namespaces are there because they uniquely identify the properties within the object;

Microsoft CDO for Windows 2000 enlists the use of Uniform Resource Identifiers (URIs) to qualify or scope field names and their semantic definitions. Each field accessed through a Fields collection is comprised of a namespace prefix and a local name. The namespace prefix is a URI reference used to qualify or scope the semantic definition of the property. For example, the subject field for a message has two representations: one with non US-ASCII characters encoded using the mechanism defined in RFC 1522, and another where these characters are decoded into native, UNICODE characters. By using namespaces, one can identify which semantic definition is intended when the "subject" for the message is requested. In this case, the subject field defined within the urn:schemas:mailheader: namespace is defined to be the US-ASCII string value of the field, and the subject field defined within the urn:schemas:httpmail: namespace is the native, UNICODE version.

From the MSDN article Fields.

It's almost exactly the same principal as XML Namespaces, or even namespaces in a language like C#

They aren't actually connecting to Microsoft at all; indeed, try typing the URL into a browser, and you will get a 404 error.

It's just the rather inelegant syntax for setting the properties that you need to set in order to connect to your exchange server.

For example, to set the server your code should connect to for sending mail, you set the property smtpserver. Internally, to reach this property, the assembly will map this onto the URI http://schemas.microsoft.com/cdo/configuration/smtpserver

A C# component for sending mail might ask you to set SmtpMail.Server. However, remember, to create SmtpMail, you would have had to look in the namespace System.Web.Mail - so the fully qualified path to the property is System.Web.Mail.SmtpMail.Server Here, however, the language is far more elegant - the using statement allows us to be in the context for creating the object, which reduces the amount of typing. Remember, if you really wanted to, in C#, you could do:

System.Web.Mail.SmtpServer mailServer = new System.Web.Mail.SmtpServer();

Which is more verbose.

In my opinion, the URI syntax is ungainly, however, at the time, it was a proposed solution to the problem of uniquely distinguishing things with the same name that could mean something different. Some people used it. A lot of people didn't. Remember, this code is over a decade old!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top