When you have a hosted site, many sites will just let you run the standard ASP.Net code to send an email, but some hosts now are requiring the login details (credentials) be put in the script you run, so as to authenticate your script.
To do this, all you need to do is to add a couple of more lines, adding your login name and password to your script.
First, of course, you must create and instantiate your smtp object:
VB Dim SmtpMail as New SmtpClient("mail.YourDomain.com")
or:
C# SmtpClient SmtpMail = new SmtpClient("mail.YourDomain.com");
Then, just put in:
VB Dim SMTPUserInfo as System.Net.NetworkCredential = new System.Net.NetworkCredential("YourUserName", "YourPassword") SmtpMail.UseDefaultCredentials = false SmtpMail.Credentials = SMTPUserInfo
or:
C# System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("YourUserName", "YourPassword"); SmtpMail.UseDefaultCredentials = false; SmtpMail.Credentials = SMTPUserInfo;
(keep in mind that the NetworkCredential line have been chopped in half, showing two lines instead of one)
All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF
Leave a reply
You must be logged in to post a comment.