Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SmtpClient

Status
Not open for further replies.

sacsac

Programmer
Dec 10, 2000
177
GB

I am trying unsuccessfully to use the SmtpClient to send an email. The following code generates an error and fails. Any ideas?

Dim email As New Net.Mail.MailMessage(<Sender>, <Recipient>)
email.Subject = "My Subject"
email.Body = "My Body Text"

Dim MySmtp As New SmtpClient(<MyServerName>, <MySMTPPort>)
MySmtp.Credentials = New Net.NetworkCredential(<MySMTPServerLogin>, <MySMTPServerPassword>)
MySmtp.UseDefaultCredentials = True
MySmtp.DeliveryMethod = SmtpDeliveryMethod.Network
MySmtp.Send(email)
 

What is the error?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
The error is "#5 Mailbox unavailable. Server requires authentication." But I think I am doing this with the line:

MySmtp.Credentials = New Net.NetworkCredential(<MySMTPServerLogin>, <MySMTPServerPassword>)


 
This line:

MySmtp.UseDefaultCredentials = True

tells the SMTPClient to use the credentials of the currently logged-in user, not the credentials supplied with .Credentials. Try removing this line and see how it works.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top