Tuesday, April 10, 2012

Send Mail From WPF using Godaddy Email Account

This is more for personal reference but might help a few people.
If you have godaddy as a host,  have the free email, paid extra email accounts (etc) and have your smtp relays set greater than zero you can send mail through your desktop app.

'must have a legitimate email setup with smtp relays set greater than 0 in your godaddy control panel (email accounts) 
Private Sub btnSendMessage_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnSendMessage.Click
      CreateTimeoutTestMessage("smtpout.secureserver.net") 'This is standard with most email relays at godaddy
  End Sub
  Public Shared Sub CreateTimeoutTestMessage(server As String)
      Dim [to] As String = "busted@fbi.gov"
      Dim from As String = "billyjoebob@hillbilly.com"
      Dim subject As String = "Catch Me If You Can."
      Dim body As String = "This is the body of the message. Yada Yada Yada"
      Dim message As New MailMessage(from, [to], subject, body)
      Dim client As New SmtpClient(server, 80)
      Console.WriteLine("Changing time out from {0} to 100.", client.Timeout)
      client.Timeout = 100
     
      'important otherwise it will timeout
      client.UseDefaultCredentials = False
      Dim basicAuthInfo As New NetworkCredential("support@yourfirm.com", "yourpassword")'real email account info setup at godaddy
      client.Credentials = basicAuthInfo
 
      Try
          client.Send(message)
      Catch ex As Exception
          Console.WriteLine("Exception caught in CreateTimeoutTestMessage(): {0}", ex.ToString())
      End Try
  End Sub