简体   繁体   中英

CDO Email Configuration

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();

I've attempted using 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();
            }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM