Link to home
Start Free TrialLog in
Avatar of colchar1973
colchar1973

asked on

Sending Mail in .Net 2005

Below is the code i have been using to send mail in .Net 2003 for a while now quite successfully. I have upgraded to .Net 2005 and this no longer works. Can anybody help me with the changes that are needed to make this workable in 2005.

Thanks in advance.


Imports System.IO
Imports System.Web.Mail


 Function GetEmailBody(ByVal strFileName As String) As String
        Dim srTemplate As StreamReader
        srTemplate = File.OpenText(Server.MapPath(strFileName))
        GetEmailBody = srTemplate.ReadToEnd
        srTemplate.Close()
    End Function

    Private Sub SendEmail(ByVal strTo As String, ByVal strBody As String)
        Dim myMessage As New MailMessage
        Dim myMail As SmtpMail

        myMessage.BodyFormat = MailFormat.Html
        myMessage.From = "admin@domain.com"
        myMessage.To = strTo
        myMessage.Subject = "email subject"
        myMessage.Body = strBody

        myMail.SmtpServer = "relay-hosting.secureserver.net"
        myMail.Send(myMessage)
    End Sub

Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnEmail.Click
              Dim strEmailBody As String = GetEmailBody("email.html")
              strEmailBody = strEmailBody.Replace("##Address##", Session("Email"))
              SendEmail(Session("Email"), strEmailBody)
 End Sub


ASKER CERTIFIED SOLUTION
Avatar of Swapnil
Swapnil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of colchar1973
colchar1973

ASKER

Thanks for your help guys, seems even though my old code is show error lines in .Net it actually works perfectly, so i am going to stick with it for the moment. I will split the points between you, hope thats ok.

Thanks
Colin