I have tried using the sample to send email to my postmaster account, but cannot get it to work. I can login and send email to and from the SmarterMail account. The Stack Trace has the errors: [SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions 64.79.170.149:25] [WebException: Unable to connect to the remote server] [SmtpException: Failure sending mail.] https://support.winhost.com/kb/a650/how-to-send-email-in-asp_net.aspx Below is the VB code. Imports System.Net.Mail Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim strFrom = "[email protected]" Dim strTo = "[email protected]" Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo)) MailMsg.BodyEncoding = Encoding.Default MailMsg.Subject = "This is a test" MailMsg.Body = "This is a sample message using SMTP authentication" MailMsg.Priority = MailPriority.High MailMsg.IsBodyHtml = True 'Smtpclient to send the mail message Dim SmtpMail As New SmtpClient Dim basicAuthenticationInfo As New System.Net.NetworkCredential("[email protected]", "password") SmtpMail.Host = "mail.HostingAccountDomain.com" SmtpMail.UseDefaultCredentials = False SmtpMail.Credentials = basicAuthenticationInfo SmtpMail.Send(MailMsg) lblMessage.Text = "Mail Sent" End Sub Any help is appreciated. Dennis
Domain name and password are correct. I can log into the postmaster account using them. I added Full Trust to the web.config file, but I am getting the same errors.
I finally got a sample working on the server, but I got errors on VS2013. Here is the VB code I used. Hope it helps someone. ==================== Imports System.Net.Mail Public Class Winhost Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strFrom = "[email protected]" Dim strTo = "[email protected]" Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo)) MailMsg.BodyEncoding = Encoding.Default MailMsg.Subject = "This is a test" MailMsg.Body = "This is a sample message using SMTP authentication" MailMsg.Priority = MailPriority.High MailMsg.IsBodyHtml = True 'Smtpclient to send the mail message Dim SmtpMail As New SmtpClient System.Net.NetworkCredential("[email protected]", "password") SmtpMail.Host = "mail.electrihelp.com" SmtpMail.UseDefaultCredentials = False SmtpMail.EnableSsl = False 'SmtpMail.Credentials = basicAuthenticationInfo SmtpMail.Credentials = New System.Net.NetworkCredential("[email protected]", "password") SmtpMail.Send(MailMsg) lblMessage.Text = "Mail Sent" End Sub End Class