Reputation: 5896
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 = "[email protected]";
msg.To = "[email protected]";
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("[email protected]");
msg.To.Add(new System.Net.Mail.MailAddress("[email protected]"));
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();
}
Upvotes: 1
Views: 5675
Reputation: 7200
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.
Upvotes: 1