开发者

SMTP server name settings

开发者 https://www.devze.com 2023-01-25 15:03 出处:网络
Hello my smart friends i have this contact form that i am working on. I want visitors to send me email through the form. I am using godaddy as my web hoster. From the below code can someone help me ho

Hello my smart friends i have this contact form that i am working on. I want visitors to send me email through the form. I am using godaddy as my web hoster. From the below code can someone help me how to setup SMTP using godaddy so i can receive emails from users on my site? I tried to use it on my local computer but i don't know how to go about. The code is below: Please can u describe me this line of codes :Dim mailServerName As String = "SMTP.MyDomain.com" AND

(from, "onfire4godcollins@gmail.com", "feedback", body)

Imports System.Net.Mail


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        If txtComments.Text.Length > 300 Then
            args.IsValid = False
        Else
            args.IsValid = True
        End If
    End Sub

    Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
        SendMail(txtEmail.Text, txtComments.Text)
    End Sub

    Private Sub SendMail(ByVal from As String, ByVal body As St开发者_运维技巧ring)
        Dim mailServerName As String = "SMTP.MyDomain.com"
        Dim message As MailMessage = New MailMessage(from, "onfire4godcollins@gmail.com", "feedback", body)
        Dim mailClient As SmtpClient = New SmtpClient

        mailClient.Host = mailServerName
        mailClient.Send(message)
        message.Dispose()
    End Sub
End Class

Thank u very much


Dim mailServerName As String = "SMTP.MyDomain.com"

This line of code is setting the name of the server that you use. It may be something like mail.godaddy.com or mail.yourdomain.com or something of that nature. If you have mail services through your provider (GoDaddy) then you'll want to check with them as to what their outgoing (SMTP) mail server is. They may also have other settings you need to keep in mind (such as authentication, SSL, port number, etc.) as well.

Dim message As MailMessage = New MailMessage(from, "onfire4godcollins@gmail.com", "feedback", body)

This line of code is creating a MailMessage object to send to the server. It's instantiating it with a "from" address which was passed to the method, a specific "to" address (which I assume is you), a specific "subject" line (feedback) and the message body which was passed to the method.

If you're trying to run this code on your local machine as-is then you're probably finding that it throws an exception when attempting to connect to SMTP.MyDomain.com since I'm guessing that doesn't exist. It'll need the real value of your SMTP server. Keep in mind that your provider's server may also not be accessible from your local computer, possibly only from their host.

(Note: If that's your actual email address, you may want to edit it out of the question, and I'll edit it out of my answer as well.)

0

精彩评论

暂无评论...
验证码 换一张
取 消