Results 1 to 4 of 4

Thread: How To Send SMTP Email (Not Gmail)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    How To Send SMTP Email (Not Gmail)

    I am trying this example code but it is not working for some reason it just hangs, I think it is hanging at "Smtp_Server.Send(e_mail)" but I do not know why.. let me know what you think.
    All the Send SMTP Mail Examples are mostly how to send from Gmail but I need to send from my actual VPS hosting not Gmail..


    Code:
    Try
    
                Dim Smtp_Server As New SmtpClient
    
                Dim e_mail As New MailMessage()
    
                Smtp_Server.UseDefaultCredentials = False
    
                Smtp_Server.Credentials = New Net.NetworkCredential("admin@example.com", "password")
    
                Smtp_Server.Port = 465
    
                Smtp_Server.EnableSsl = True
    
                Smtp_Server.Host = "mail.example.com"
    
                e_mail = New MailMessage()
    
                e_mail.From = New MailAddress("admin@example.com")
    
                e_mail.To.Add("myemail@where_ever.com")
    
                e_mail.Subject = "TEST - Email Sending"
    
                e_mail.IsBodyHtml = False
    
                e_mail.Body = "example test message"
    
                Smtp_Server.Send(e_mail)
    
                MsgBox("Mail Sent")
    
            Catch error_t As Exception
    
                MsgBox(error_t.ToString)
    
            End Try
    
        End Sub

  2. #2
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: How To Send SMTP Email (Not Gmail)

    Did u just copy paste some random code from the interner?
    I'm pretty sure that host "mail.example.com" doesn't exist. As do many other variables in that example.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: How To Send SMTP Email (Not Gmail)

    Don't mind the actual addresses, I had my real VPS hosting account credentials in there but good observation my friend. This is an example that I did find but had my correct hosting VPS addresses in the code before posting this. Took them out for privacy/security reasons.. Just wanted to know why it is not sending the email when I used my proper and working details.

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: How To Send SMTP Email (Not Gmail)

    I think it is hanging at "Smtp_Server.Send(e_mail)" but I do not know why

    Try the following with Visual Studio "Output" window open.

    http://www.systemnetmail.com/faq/4.6.aspx

    Code:
       Sub SendAsync()
            'create the mail message
            Dim mail As New MailMessage()
    
            'set the addresses
            mail.From = New MailAddress("me@mycompany.com")
            mail.To.Add("you@yourcompany.com")
    
            'set the content
            mail.Subject = "This is an email"
            mail.Body = "this is the body content of the email."
    
            'send the message
            Dim smtp As New SmtpClient("127.0.0.1") 'specify the mail server address
            'the userstate can be any object. The object can be accessed in the callback method
            'in this example, we will just use the MailMessage object.
            Dim userState As Object = mail
    
            'wire up the event for when the Async send is completed
            AddHandler smtp.SendCompleted, AddressOf SmtpClient_OnCompleted
    
            smtp.SendAsync(mail, userState)
        End Sub 'SendAsync
    
        Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
            'Get the Original MailMessage object
            Dim mail As MailMessage = CType(e.UserState, MailMessage)
    
            'write out the subject
            Dim subject As String = mail.Subject
    
            If e.Cancelled Then
                Console.WriteLine("Send canceled for mail with subject [{0}].", subject)
            End If
            If Not (e.Error Is Nothing) Then
                Console.WriteLine("Error {1} occurred when sending mail [{0}] ", subject, e.Error.ToString())
            Else
                Console.WriteLine("Message [{0}] sent.", subject)
            End If
        End Sub 'SmtpClient_OnCompleted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width