Hello House,
I am working on project that requires sending mail notifications, the smtp server requires that the from address be specified with the ip, i have done this and it is working, but going to deploy the application, i am only given an ip address, i have tried sending mails with only ip address but it is not working, the error message is: No connection could be made because the target machine actively refused it 10.90.17.203:25
i suspect the mail server requires some sort of authentication, the client insists that he gives only the ip to other vendors, and they have been able to send mail with it. Please i need your assistance, if this could be done. here is my code:
static void CreateMail(string recipient, string subject, string msg)
{
Configuration oConfig = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None );
var mailSettings = oConfig.GetSectionGroup( "system.net/mailSettings" ) as MailSettingsSectionGroup;
var mailRecipients = ( ConfigurationManager.AppSettings["MailRecipients"] );
if (mailSettings != null)
{
var from = mailSettings.Smtp.From;
var host = mailSettings.Smtp.Network.Host;
var pwd = mailSettings.Smtp.Network.Password;
var uid = mailSettings.Smtp.Network.UserName;
try
{
var message = new MailMessage();
message.To.Add(recipient);
message.Subject = subject;
message.From = new MailAddress(from);
message.Body = msg;
message.Priority = MailPriority.Normal;
var smtp = new SmtpClient(host);
smtp.Credentials = new System.Net.NetworkCredential(uid, pwd);
smtp.Send(message);
smtp.Dispose();
Log.Info("Mail sent successfully to the following recipients: " + "\n\r\n\r " + mailRecipients);
}
catch (SmtpException ep)
{
Log.Error(ep.ToString() + "\n\n\r " + ep.StackTrace);
}
}
My Config file:
<system.net>
<mailSettings>
<smtp from="mpeter@iqs-solutions.com">
<network host="192.168.0.100" userName="mpeter@iqs-solutions.com" password="Sirpic.80"/>
</smtp>
</mailSettings>
</system.net>