can't send Email from Webservice written in vb.net - vb.net

I wanna send an Email from my Webservice, written in vb.net, but I get an Timeout.
What is wrong?
Dim toaddress As MailAddress = New MailAddress("xxx")
Dim fromaddress As MailAddress = New MailAddress("yyy")
' The structure for MailMessage(from, to)
Dim message As MailMessage = New MailMessage(fromaddress, toaddress)
message.Subject = "I have sent you a message from a program!"
message.Body = "Hello World!"
Dim messanger As SmtpClient = New SmtpClient("smtpxxx", 995)
messanger.Credentials = New NetworkCredential("user", "password")
messanger.EnableSsl = True
messanger.Send(message)

You are doing many things wrong and some of the information you have given are not clear enough. host name and port names have to give properly. it chooses which mail service you are using, from your code it is not correctly provided, so i will give a snippet that uses gmail to send mail. please go through this and make changes as per your SmtpHost.
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
This link help you to find the smtp.Server and Port numbers, you can use this thread for check the limitations of smtp.servers

Related

Sending Email - VB.Net - Windows Form

I have tried different port numbers but I keep getting the error message and no email sent. I aim to be able to send the email successfully and the message will contain details from an appointment booked. Any help please?
Dim UserName As String = "example#gmail.com"
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress(UserName)
mail.To.Add(New MailAddress(txtEmailAddress.Text))
mail.Subject = "Appointment Details"
mail.Body = "Test message"
mail.IsBodyHtml = True
Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 465)
client.EnableSsl = True
client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Try
client.Send(mail)
Catch ex As Exception
MessageBox.Show("Sending email failed. Please Try again")
End Try
What you need to do is add client.UseDefaultCredentials = False, but make sure you set it to false before calling client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Also, for GMail, you need to use port 587 which is the port that supports the STARTTLS extension (which is the only way that System.Net.Mail.SmtpClient supports SSL).
In other words, change your code to this:
Dim UserName As String = "example#gmail.com"
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress(UserName)
mail.To.Add(New MailAddress(txtEmailAddress.Text))
mail.Subject = "Appointment Details"
mail.Body = "Test message"
mail.IsBodyHtml = True
Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Try
client.Send(mail)
Catch ex As Exception
MessageBox.Show("Sending email failed. Please Try again")
End Try
Try this,
go to your gmail account (www.gmail.com)
login, and check that you have "enabled Pop for all mail".
you can find this under the tab "Forwarding and POP/IMAP"
Also try switching the port number to 587

getting error when i am sending mail via smtp

Dim MESSAGE As New MailMessage()
MESSAGE.From = New MailAddress(Mail_From)
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.To.Add(email)
MESSAGE.Subject = "Testing"
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.Body = msg
Dim smtp As New SmtpClient()
smtp.Host = SMTP_Host
smtp.Port = SMTP_Port
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential(Mail_User, Mail_PW)
smtp.EnableSsl = False
smtp.Send(MESSAGE)
i got error:
MAIL Error Message:Mailbox unavailable. The server response was:
This email has identified as high probability of being a spam mail
by our
The mail has been rejected by the server, there is nothing you can do to resolve this. You could in theory attempt to modify the content so that is does not appear as spammy, but this is likely to be a long and tedious process.

Email not send using Gmail smtp on host

I've used this code to sending emails. When I test this code in LOCALHOST, it works correctly, but in host, I get this error:
Failure sending mail.few
My code is:
Dim MailMsg As New MailMessage(New Net.Mail.MailAddress("MYUSERNAME#gmail.com"), New Net.Mail.MailAddress("myname#gmail.com"))
MailMsg.Subject = "test"
MailMsg.Body = "test"
MailMsg.IsBodyHtml = True
Dim SmtpMail As New Net.Mail.SmtpClient
Dim SMTPUserInfo As New Net.NetworkCredential()
SMTPUserInfo.UserName = "MYUSERNAME"
SMTPUserInfo.Password = "MYPASSWORD"
SmtpMail.UseDefaultCredentials = False
SmtpMail.Credentials = SMTPUserInfo
SmtpMail.Host = "smtp.gmail.com"
SmtpMail.Port = 587
SmtpMail.EnableSsl = True
SmtpMail.Send(MailMsg)
'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("USERNAME#gmail.com")
'To is a collection of types
MyMailMessage.To.Add("DESTINATION#EXAMPLE.COM")
MyMailMessage.Subject = "XXXXXXX" & x
MyMailMessage.Body = "XXXXXXXXXXXXXXXXXXX "
Dim attach As New Attachment(fileName)
MyMailMessage.Attachments.Add(attach)
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("USERNAME#gmail.com", "PASSWD")
SMTPServer.EnableSsl = True
SMTPServer.Send(MyMailMessage)
SMTPServer.Dispose()
MyMailMessage.Dispose()

Send email using smtp but operation timed out using ZOHO

Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(abc#zoho.com,abc123)
Smtp_Server.Port = 465
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.zoho.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(abc#zoho.com)
e_mail.To.Add("david#hotmail.com")
e_mail.Subject = "Testing"
e_mail.IsBodyHtml = False
Smtp_Server.Send(e_mail)
Return True
Now I trying to send email to other person but the error show me the operation timed out, when using ZOHO to send. And I got find the solution but still fail to send. How can I solve it?
Try to use PORT : 587
Smtp_Server.Port = 587

Sending Mail in Vb.net using vb.net

Am using the below code to send a mail in vb.net, this code works fine with gmail but not works with rediffmail
Mail.Subject = "test email"
Mail.To.Add(dgr.Cells("to#xyz.com")
Mail.From = New MailAddress("from#abc.com")
Mail.Body = "Hello"
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("AttachPath")
Mail.Attachments.Add(attachment)
Dim SMTP As New SmtpClient("smtp.rediffmailpro")
SMTP.EnableSsl = false
SMTP.Credentials = New System.Net.NetworkCredential("xyz#.abc.com",
"password")
SMTP.Port = 25
SMTP.Send(Mail)
any reason? or solution, so that I can sent mail using any Email ID
Try
Dim SMTP As New SmtpClient("smtp.rediffmailpro.com")