Click here to Skip to main content
15,898,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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 mailAttachment = (System.Configuration.ConfigurationManager.AppSettings["MailAttachment"]);
            var mailRecipients = ( ConfigurationManager.AppSettings["MailRecipients"] );

            if (mailSettings != null)
            {
                //int port = mailSettings.Smtp.Network.Port;
                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.Bcc =bcc;
                    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:

C#
<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>
Posted

http://www.c-sharpcorner.com/Blogs/11147/send-email-in-Asp-Net-by-your-ip-without-email-id-and-passwo.aspx[^]



Try the above link. Read the comments as well in the link to make use of it.
 
Share this answer
 
Comments
Uwakpeter 6-Aug-14 3:08am    
Thanks Arut, i have gone through the post on that link, from what i am getting the mail wont be sent to recipient mailbox, but kept in the IIS in c directory, and can only send to one address per time. i needed to send to recipient's inbox and can also specify comma delimited list of email addresses.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900