Jump to content
xisto Community
Sign in to follow this  
jimmy89

Sending Mail In Vb.net

Recommended Posts

Hi,
I am trying to allow my program to send emails via a smtp server. Everything seems to be working the only problem is that i get an error response from the server saying

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required

The Code that I am using is
Private Sub SendMail()		Dim fromAddress As New MailAddress("from@mail.com", "Support")		Dim toAddress As New MailAddress(txtEmail.Text, "User")		Dim msg As New MailMessage(fromAddress, toAddress)		msg.Body = My.Application.Info.DirectoryPath + "\support\mailtemplate.html"		msg.Subject = "Support Ticket"		msg.IsBodyHtml = True		Dim mailSender As New System.Net.Mail.SmtpClient()		mailSender.Host = "mail.myserver.com"		mailSender.Port = 587		Try			mailSender.Send(msg)			MsgBox("Message sent")		Catch ex As Exception			MsgBox(ex.Message)		End TryEnd Sub

All I think I have to do is set up authentication for the server, but im not sure how to do that!
Thanks,
-jimmy
Edited by Jimmy89 (see edit history)

Share this post


Link to post
Share on other sites

Ya, most SMTP server now require authentication to send email, as a spam prevention feature, but i still receive as much spam or even more nowadays :rolleyes:

Try add these code

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here

I copied the 3 lines of code from http://www.systemwebmail.com/faq/3.8.aspx

I haven't got time to test it out. Give it a try and post the result here.

Good Luck

Share this post


Link to post
Share on other sites

I seem to be getting my fair share of spam also, your not alone! :rolleyes:

I went to the website and found that if I'm using .net 2 (which I am) I can use different code.

Sub Authenticate()		'create the mail message		Dim mail As New Net.Mail.MailMessage()		'set the addresses		mail.From = New Net.Mail.MailAddress("me@mycompany.com")		mail.To.Add("you@yourcompany.com")		'set the content		mail.Subject = "This is an email"		mail.Body = "this is the body content of the email."		'send the message		Dim smtp As New Net.Mail.SmtpClient("127.0.0.1")		'to authenticate we set the username and password properites on the SmtpClient		smtp.Credentials = New Net.NetworkCredential("username", "secret")		smtp.Send(mail)	End Sub 'Authenticate

This was from: http://www.systemnetmail.com/faq/4.2.aspx

yet this still returns the same error!

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required

EDIT: I attempted using my Xisto smtp details and now get a Failure Sending Mail error. The Inner Exception is

Unable to read data from the transport connection: net_io_connectionclosed.

Edited by Jimmy89 (see edit history)

Share this post


Link to post
Share on other sites

You can try sending through a working SMTP server, say, your existing SMTP server for your normal email provider. That way, you can eliminate the problem which might be caused by the server itself

Share this post


Link to post
Share on other sites

faulty, that should have been my first thought! it worked! which leads me to wonder why its not working with Xisto? It must be something to do with the server and the way mail is setup through CPanel.

Share this post


Link to post
Share on other sites

I have the same problem. I tried using the example above but I' still getting this error message. 

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required.

is there any other reason for this behavior?

Thanks for your help.

Tony

Share this post


Link to post
Share on other sites

try to use SSL encryption;

 Dim smtp As New System.Net.Mail.SmtpClient smtp.Host = "your host goes here" smtp.Port = "ypur host port goes here" smtp.EnableSsl = True ' this is the important thing smtp.Send([MailMessage])

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.