c# - Need help setting up SMTP -
I am having a strange problem and I'm not sure why.
I have this in my webconfig
& lt; Add Key = "SMTP" value = "mail.reliablesite.net" /> & Lt; Add key = "email" value = "email" /> & Lt; Add Key = "EMAIL_PASSWORD" Value = "Password" /> & Lt; Add Key = "FROM_PORT" value = "2525" />
Now when I test SMTP through a local host, it's all right and sends my SMTP and everything. I upload my webconfig plus all my other files and I try to test my SMTP and no message is sent. Perfect code and everything.
So I do not know why this does not work.
This is like a short version of my code.
Public class MyTestController: Controller {// // GET: / MyTest / public void index () {Mail Message Mail = New MailMessage (); similarity. From = new mail address ("to"); Mail.To.Add ("for"); Mail.Subject = "Topic"; Mail.IsBodyHtml = True; similarity. Body = "body"; Network credential credentials = new network credentials ("emailframehosthosting site", "password"); SmtpClient smtp = new SmtpClient (); Smtp.host = "mail.reliablesite.net"; Smtp.Port = 2525; Smtp.Credentials = Credentials; Smtp.Send (mail); Mail.Dispose (); }}
-
I instead use System.Net settings I suggest to do The app settings make sure that when you take a method or property on SMTPClient, you get the setting automatically.
-
Now - your question is coming up, as the other told that the SMTP port is sometimes, SMTP is using a specific port on the server You have to configure and you must configure it in your config file. You can try the following code to send mail through a Gmail account with your code. Use an attempt to wrap Smtp.send (). And check if you are getting any exceptions.
Comments
Post a Comment