TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Surekha Gund
NA
52
1.7k
The SMTP server requires a secure connection
Oct 2 2014 3:37 AM
This is my code for
Sending Email to Multiple Recipients it throws an exception
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
public static void SendEmail(string ToEmail, string subject, string message)
{
//Reading sender Email credential from web.config file
HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
Pass = ConfigurationManager.AppSettings["Password"].ToString();
//creating the object of MailMessage
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(FromEmailid); //From Email Id
mailMessage.Subject = subject; //Subject of Email
mailMessage.Body = message; //body or message of Email
mailMessage.IsBodyHtml = true;
//Adding Multiple recipient email id logic
string[] Multi = ToEmail.Split(','); //spiliting input Email id string with comma(,)
foreach (string Multiemailid in Multi)
{
mailMessage.To.Add(new MailAddress(Multiemailid)); //adding multi reciver's Email Id
//mailMessage.To.Add("
[email protected]
");
}
SmtpClient smtp = new SmtpClient(); // creating object of smptpclient
smtp.Host = HostAdd; //host of emailaddress for example smtp.gmail.com etc
//network and security related credentials
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = mailMessage.From.Address;
NetworkCred.Password = Pass;
// smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mailMessage); //sending Email
}
Reply
Answers (
1
)
About base in C#
Make a instant app