I checked here: https://forums.asp.net/t/1483523.aspx?where+do+you+place+the+mail+settings+in+the+web+config+file+ and added to my web.config:Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
Code: Select all
<system.net>
<mailSettings>
<smtp from="info@mydomain.com">
<network host="localhost" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
When I send via localhost it works fine, but when I send using credentials and a full domain name like so:
Code: Select all
Dim Msg As MailMessage
Dim mailObj As New SmtpClient
mailObj.Host = "smtp.mydomain.com"
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("info@mydomain.com", "mypassword")
mailObj.UseDefaultCredentials = False
mailObj.Credentials = basicAuthenticationInfo
Msg = New MailMessage
Dim To_Addr As MailAddressCollection = Msg.To
To_Addr.Add(New MailAddress("john@gmail.com", "john@gmail.com"))
Msg.From = New MailAddress("info@mydomain.com", "mydomain")
mailObj.Send(Msg)