This is web config
<appSettings>
<add key="SmtpServer" value="gmail.com"/>
<add key="SmtpUtilisateur" value="superman@gmail.com"/>
<add key="SmtpPassword" value="12345678"/>
</appSettings>
This my vb method
Sub SendSimpleMail()
Dim Message As New Mail.MailMessage
Dim utilisateur As String
Dim pass As String
Dim server As String
utilisateur = ConfigurationSettings.AppSettings("StmpUtilisateur")
pass = ConfigurationSettings.AppSettings("SmtpPassword")
server = ConfigurationSettings.AppSettings("SmtpServer")
Message.From = "superman@gmail.com"
Message.To = "superman@gmail.com"
Message.Subject = "test"
Message.Body = "salut je voulais savoir comment tu allais"
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", utilisateur)
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtppassworld", pass)
SmtpMail.SmtpServer = server
Try
SmtpMail.Send(Message)
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
I get an error like the “transport fail in connection to server”
I don’t know why this is not work well…
Thank’s for helping me!
This in vb.net
First, it is recommended to use
System.Net.Mailinstead ofSmtpMail, since the latter has been declared obsolete by Microsoft.Second, the Gmail SMTP server requires a secure connection which can be set using
SmtpClient.EnableSsl.Your example could be changed to the following:
If you replace the
appsettingsin the web.config with the following specific block, the SmtpClient will automatically configure itself accordingly:This would reduce your method to: