Configuración de correo electrónico de CDO

I'm attempting to send email using CDO. I'm wanting to change the settings to always send from a specific smtp server with a specific user, pass, and from. However, when I attempt to change the config, I get an error that the data is readonly. How do you go about changing the config of the message?

Message msg = new Message();
            IConfiguration config = msg.Configuration;
            config.Fields["smtpserver"] = "SERVER";
            msg.Subject = "TEST";
            msg.From = "FROM@FROM.com";
            msg.To = "TO@TO.com";
            msg.TextBody = "TESTING";
            msg.Send();

He intentado usar System.Net.Mail, but that seems to be firewall blocked. I get the exception message Unable to connect to the remote server : No connection could be made because the target machine actively refused it {IP}:67

MailMessage msg = new MailMessage();
            msg.Subject = "TESTING";
            msg.From = new MailAddress("MYMAIL@MYMAIL.org");
            msg.To.Add(new System.Net.Mail.MailAddress("TOMAIL@TOMAIL.org"));
            msg.Body = "dubbly doo";

            SmtpClient client = new SmtpClient();
            client.Host = "HOST";
            client.Port = 67;
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                client.Send(msg);
            }
            catch(SmtpException e)
            {
                Console.Write(e.InnerException.Message+":"+e.InnerException.InnerException.Message);
                Console.ReadLine();
            }

preguntado el 03 de mayo de 12 a las 15:05

If one is blocked at the firewall, both will be blocked. If CDO is not blocked, then .Mail shouldn't be blocked either. Likely it is either misconfigured or the SMPT service is not installed locally. -

@JoelEtherton CDO works, but I can't change the configuration. With SMTP I get the exception message <<Unable to connect to the remote server : No connection could be made because the target machine actively refused it {IP}:67>> -

1 Respuestas

Is using CDO a requirement? You are already using C#, so I recommend porting your CDO code to System.Net.Mail.

http://msdn.microsoft.com/en-us/library/dk1fb84h.aspx

Edit:

Since it sounds in the comments like you are having configuration issues with System.Net.Mail, I would use some of the SysInternals tools (specifically TcpView) to monitor your connections as you step through the CDO code. That way you can see what IP and ports your code is using to connect.

Then armed with that information, you should be able to configure your System.Net.Mail code with the correct settings.

contestado el 03 de mayo de 12 a las 16:05

cdo? more like cdon't amirite - Snuffleupagus

I'd prefer to use System.Net.Mail actually, but the firewall seems to be blocking it. However, CDO doesn't seem to be blocked. I'm assuming the direct Exchange use of CDO is allowed or something. Maybe my SMTP settings are just off. I've posted those above as well now. - Steventnorris

Is there a reason you are using port 67? Standard for SMTP is 25. In any case, firewalls only block IP/port combinations. I can't think of a reason why CDO would work and System.Net.Mail wouldn't, other than incorrect configuration. - mgnoonan

@mgnoonan I've tried port 25 as well with the same issue. 67 was listed as the default port on the msdn for CDO.IConfiguration so I gave it a try. I've added teh specific exception above for clarification. I'm not 100% sure why I'm getting it, but it seems to be a firewall issue. - Steventnorris

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.