Dim mail As New Net.Mail.MailMessage()
mail.From = New Net.Mail.MailAddress("abc#xyz.com")
mail.[To].Add("abc#xyz.com")
mail.IsBodyHtml = True
mail.Subject = "A subject line."
mail.Body = "A mail body message."
Dim smtp As New Net.Mail.SmtpClient("smtp.xyz.com", 25)
smtp.Credentials = New System.Net.NetworkCredential("abc#xyz.com","password")
Try
smtp.Send(mail)
MsgBox("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
MsgBox("Send failure: " & exc.ToString())
End Try
In Windows Application a simple SMTP using Credential, throwing Exception-
Failure sending mail.
Why it is throwing can anybody help me out.
Related
I have an Simple Application that Sends and email as Follows:
Private Sub sendEmail()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(cmbFrom.Selected.Value)
mail.[To].Add(cmbTo.Selected.Value)
mail.IsBodyHtml = True
'set the content
mail.Subject = getSubject()
mail.Body = getBody()
If cmbSubj.Selected.Description = "Confirmation" Then
mail.Headers.Add("Disposition-Notification-To", cmbFrom.Selected.Value)
End If
'set the server
Dim smtp As New SmtpClient("Mail.MyDomain.Co.Uk")
'smtp.UseDefaultCredentials = True
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
'send the message
Try
smtp.Send(mail)
Application.SBO_Application.MessageBox("Your Email has been sent sucessfully - Thank You")
oForm.Close()
Catch exc As Exception
Application.SBO_Application.MessageBox("Send failure: " & exc.ToString())
End Try
End Sub
and this Exchange Server Mail Flow Rule:
Unfortunately the mail flow rule is not applying to messages,
How can i ensure this Mail Flow rule applies to the App based Emails and why Has it been ignored so far?
Changing the Mail Flow Rule Resolved the issue, However the question of why the rules were missed when using the smtpClient Remains.
To resolve the rule was changed to "The Sender Address Matches..." and the Domain name.
mail flow rule 2
I want to send an email when user click btnSubmit. My problem is when I click the btnSubmit it gives me error at Catch ex As Exeption. I'm using Web Form.aspx.vb
Here is my code
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress("example#gmail.com")
mail.To.Add(New MailAddress("example#gmail.com"))
mail.Subject = "TEST SUBJECT"
mail.Body = "Test Message"
mail.IsBodyHtml = True
Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
Try
client.Send(mail)
MsgBox("Sending Email succeeded") 'Return True if there is nothing error while sending email.
Catch ex As Exception
MsgBox("Sending Email failed. Please try again")
End Try
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
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.
I have a basic vb.net windows form application and is wondering how I would go about sending an email? I have no servers set up or anything like that, I was wondering if I could still send it without setting up all that stuff. This is the code I have now:
Private Sub sendEmail(ByVal golfersTable As DataTable)
'create the mail message
Dim mail As New MailMessage()
Dim SMTP As New SmtpClient()
'set the addresses
mail.From = New MailAddress("someone#gmail.com")
mail.To.Add("someone#gmail.com")
'set the content
mail.Subject = "Golf Quotas"
mail.Body = "Golfer Name" & "-----------------------------------------------" & row.Item("Average Quota")
For Each row As DataRow In golfersTable.Rows
mail.Body = row.Item("Golfer Name") & "---------------" & row.Item("Average Quota")
Next
'set the server
SMTP.EnableSsl = True
SMTP.UseDefaultCredentials = False
SMTP.Port = "465"
'SMTP.Send(mail)
Try
SMTP.Send(mail)
MsgBox("Your Email has been sent sucessfully - Thank You")
Catch ex As Exception
MsgBox("Message Failed To Send" & ex.ToString)
End Try
End Sub
I have gotten nothing to work at all from everything that I have tried.... Idk what I'm doing wrong but it's not working. I tried a nslookup www.gmail.com in cammand prompt but it said that domain not found ?
If you are using a GMail account to send the emails then you can use Google's SMTP server, smtp.gmail.com.
More details here:
http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm