Timeout while sending email on specific port with SSL enabled - vb.net

I get timeout error when I try to send an email using the port 465 and EnableSSL=True. If I change the port to 25 and EnableSSL=False I mail will be sent properly.
I use vb.net, domain email and password and I want to sent throught domain's SMTP.
Dim smtpServer As New SmtpClient()
smtpServer.Host = "ip"
smtpServer.Port = 465 ''SSL Port
smtpServer.Credentials = New System.Net.NetworkCredential(FromMail,Password)
smtpServer.EnableSsl = True
smtpServer.Send(mail)
What I need to use in order to be able to send properly from Port 465 and with SSL=True?

Use the TLS Port instead of SSL Port. This worked for me.

Related

Email Service works just fine locally but it doesn't work when the site is deployed to godaddy host

I have a function that sends email in my website. My website is written in Visual Basic and my email sender function is below:
Dim mail As New MailMessage()
mail.Subject = Trim(TextBox1.Text())
mail.Body = Trim(TextBox2.Text())
Try
Dim SmtpServer As New SmtpClient()
SmtpServer.Host = "smtpout.secureserver.net"
SmtpServer.Port = 80
SmtpServer.Credentials = New Net.NetworkCredential("test#test.org", "password")
mail.From = New MailAddress("admin#test.org")
mail.To.Add("customer#test.org")
mail.CC.Add(Trim(HiddenField1.Value()))
mail.Subject = Trim(TextBox1.Text())
mail.Body = Trim(TextBox2.Text())
mail.IsBodyHtml = True
SmtpServer.Send(mail)
Response.Redirect("Welcome.aspx", False)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
The email function and everything worked just fine on my local dev machine. But they never worked when I deployed to the windows hosting in GoDaddy.
Here is what I get as an exception:
I know that GoDaddy has some strict rules for sending emails. But to avoid this, I couldn't find good documentation. What am I missing?
The host name is probably not the right one.
SmtpServer.Host = "smtpout.secureserver.net"
Godaddy mentions this as a blanket host for most of the SMTP related requests. But, they have actually implemented a system where each user is given a sandboxed access to its SMTP service. The combination of hostname and port is used to uniquely identify the user.
You could find this in your settings, their terminology is email relay server.
Reference:
Godaddy

VB: How to send email with SMTP... Dynamically set host and port for major ISP's

I am working on a VB application that sends an HTML email. I found this, and am trying to implement it.
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(EmailFrom, "Display Name")
mail.To.Add(EmailTo)
'set the content
mail.Subject = "Subject Line"
mail.Body = "Message body"
mail.IsBodyHtml = True
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
I don't have any info on the argument passed to SmtpClient() for this code snippet.
I have found videos showing how to connect to google smtp using "smtp.gmail.com" and a specific port. However, This would only be practical if all of the users of my application will have Gmail. I don't want to force them to have one in order to have access to the functionality.
Could any of you experts provide me with some help on dynamically selecting the correct smtp server and port based on their email?
for example, email is stored in a variable called email:
Dim email As String = "me#gmail.com"
This email is coming from MySql database so how do I take variable string and check which ISP they use and then have my code use the correct smtp and port for that ISP?
Also, I've read that now days authentication is required so I will likely prompt user with input box before calling procedure that sends the email.
Here's some code showing that:
Hotmail:
Smtp.live.com
Port: 587
Gmail:
smtp.gmail.com
Port: 587
Yahoo:
smtp.mail.yahoo.com
Port: 465
Aol:
smtp.aol.co.uk
Port: 587
imports system.net.mail
dim Mail as new mailmessage
Try
mail.From = New MailAddress("FROM EMAIL")
mail.To.Add(TO EMAIL)
mail.Subject = "SUBJECT"
mail.Body = "BODY"
Dim s As New SmtpClient("HOST")
s.Port = PORT
s.EnableSsl = True
s.Credentials = New System.Net.NetworkCredential("FROM EMAIL, "FROM PASSWORD")
s.Send(Mail)
MsgBox("E-mail was sucsessfully sent!", MsgBoxStyle.Information, "Information")
Catch ex As Exception
End Try
I'm completely stumped. Any help would be greatly appreciated. I am also open to any ideas that accomplish same feat even if not in accordance with first code snippet. Thanks in advance.

Can't send SMTP e-mail

I am trying to test sending out an e-mail from vb.net. I am sending an e-mail from mygmail account to myself, however I keep getting an error message: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 587)
SmtpServer.EnableSsl = True
SmtpServer.Credentials = New Net.NetworkCredential("MYEMAILADDRESS", "MYPASSWORD")
Dim mail As New MailMessage("MYEMAILADDRESS", "MYEMAILADDRESS", "This is my Title", "This is my Email")
SmtpServer.Send(mail)
I have read a few post but all of them say change the port. I have changed the port however it doesn't seem to work. If I change the port it gives a similar error.

Visual basic 2010 send email using gmail SMTP

I want to send email from my Visual basic form
my code:
Private Sub email1()
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("MYEMAIL#gmail.com", "MYPASS")
Smtp_Server.Port = 465
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("MYEMAIL#gmail.com")
e_mail.To.Add("MYFRIENDEMAIL#gmail.com")
e_mail.Subject = "SUBJECT"
e_mail.IsBodyHtml = False
e_mail.Body = "TEXT MESSAGE"
Smtp_Server.Send(e_mail)
Catch error_t As Exception
email_status.Text = ("Error: " & error_t.Message)
MsgBox(error_t.Message)
Exit Sub
End Try
email_status.Text = ("OK")
End Sub
errors while using smtp.gmail.com
while using SMTP port 465: The operation has timed out.
while using SMTP port 587: Failure sending email.
while using SMTP port 25: Failure sending email.
errors while using smtp.googlemail.com
while using SMTP port 465: The operation has timed out.
while using SMTP port 587: Failure sending email.
while using SMTP port 25: Failure sending email.
i am using AVAST antivirus but i turned it off
can you please help me?
thank you very much.

VB.NET GMAIL SMTP Server Settings

I am using the Following Code for my GMAIL Server SMTP Settings, but am unable to send emails.
Can anyone help me out...
Dim emailClient As New SmtpClient("mail.gmail.com")
Dim SMTPUserInfo As New System.Net.NetworkCredential("xxxxx#gmail.com", "abc123")
emailClient.UseDefaultCredentials = False
emailClient.Port = 465
emailClient.EnableSsl = True
emailClient.Credentials = SMTPUserInfo
emailClient.Timeout = 1000000
emailClient.Send(mail)
emailClient = Nothing
SMTPUserInfo = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message & " Error Mails : ", Me.Text, MessageBoxButtons.OK)
End Try
I think, you should use following settings:
emailClient.Host = "smtp.gmail.com"
emailClient.port = 587
emailClient.EnableSsl = True
If you connect using SMTP, you can only send mail to Gmail or Google Apps users; if you connect using SSL/TLS, you can send mail to anyone. If your device or application supports SSL - connect to smtp.gmail.com on port 465. To connect with SSL, you need to provide a Google username and password for authentication.
Source: https://support.google.com/a/answer/176600?hl=en