View Single Post
  #7 (permalink)  
Old 16-06-2007, 10:38
EOTB EOTB is offline
Junior Member
 
Join Date: Jun 2007
Posts: 29
Default SMTP Email Sending

Hi guys and thanks for the above posts.

I have been receiving an error about unable to send to non-local addresses - eg email outside of the domain. I have created the code below to fix the issue.

Create a button on the page and also a Label with the ID of 'EmailError'.

IMPORTS:
Quote:
Imports System.Net.Mail
Imports System.Net.NetworkCredential
CODE:
Quote:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim maMailfrom As New MailAddress("[FROM EMAIL]", "[FROM NAME]")
Dim maMailTo As New MailAddress("[TO EMAIL]", "[TO NAME]")
Dim mmEmail As New MailMessage(maMailfrom, maMailTo)
mmEmail.IsBodyHtml = False
mmEmail.Subject = "[SUBJECT]"
mmEmail.Body = "[MESSAGE]
Try
Dim smtpSend As New SmtpClient("smtp.[DOMAIN]")
Dim credLogin As System.Net.NetworkCredential = New System.Net.NetworkCredential("[MAIL BOX EMAIL]", "[MAIL BOX PW]")
smtpSend.Credentials = credLogin
smtpSend.Send(mmEmail)
Catch ex As Exception
EmailError.Text = ex.ToString
End Try
End Sub
Basically replace all the []'s with want you want. I hope this makes sense to you all!
__________________
Thanks

EOTB
Reply With Quote