Winhost Sample Email for ASP.NET Not Working

Discussion in 'Email' started by Dennis Lackey, Oct 30, 2015.

  1. 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 = "postmaster@HostingAccountDomain.com"
    Dim strTo = "postmaster@HostingAccountDomain.com"
    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("postmaster@mydoamin.com", "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
     
  2. Elshadriel

    Elshadriel Winhost Staff

    Try enabling "Full" trust and make sure you are using your domain name in your code.
     
  3. 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.
     
  4. FredC

    FredC Winhost Staff

    Please open a support ticket. Need more information (account name, mail server, etc.)
     
  5. 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 = "sender@sendersemailaddress.com"
    Dim strTo = "postmaster@xxxxxx.com"
    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("postmaster@xxxxxx.com", "password")
    SmtpMail.Host = "mail.electrihelp.com"
    SmtpMail.UseDefaultCredentials = False
    SmtpMail.EnableSsl = False
    'SmtpMail.Credentials = basicAuthenticationInfo
    SmtpMail.Credentials = New System.Net.NetworkCredential("postmaster@xxxxxx.com", "password")
    SmtpMail.Send(MailMsg)
    lblMessage.Text = "Mail Sent"
    End Sub

    End Class
     
    Last edited: Oct 30, 2015
    Michael likes this.

Share This Page