Error Sending Email In Asp.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error Sending Email via SMTP on ASP.NET MVC up vote 1 down vote favorite 1 I'm trying to send email from my website using SMTP. I'm getting an error whenever I do. I tested it locally using my ISPs smtp server and it worked great. Now that i'm on the web though that's not the case. I'm not sure what the error I'm getting is other then it doesn't work and I get the error message I have programmed into the site. You can see my code below. i've tried a couple of different servers with no luck. I know the login/password is good because I verified it. My hosting provider is winhost but my email goes through gmail. So, I setup an account on godaddy that allows 250 relays. public class EmailMeController : Controller { // // GET: /EmailMe/ [AcceptVerbs(HttpVerbs.Get)] public ActionResult Index() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(EmailModel emailModel) { if (ModelState.IsValid) { bool isOk = false; try { MailMessage msg = new MailMessage(); msg.From = new MailAddress("no-reply@openskymedia.com", "Website Contact Form"); msg.To.Add("admin@openskymedia.com"); msg.Subject = emailModel.Subject; string body = "Name: " + emailModel.Name + "\n" + "Email: " + emailModel.EmailAddress + "\n" + "Website: " + emailModel.WebSite + "\n" + "Phone: " + emailModel.Phone + "\n\n" + emailModel.Message; msg.Body = body; msg.IsBodyHtml = false; SmtpClient smtp = new SmtpClient("smtp.secureserver.net", 80); NetworkCredential Credentials = new NetworkCredential("postmaster2@domain.com", "password"); smtp.Credentials = Credentials; smtp.Send(msg); msg.Dispose(); isOk = true; MessageModel rcpt = new MessageModel(); rcpt.Title = "Thank You"; rcpt.Content = "Your email has been sent."; return View("Message", rcpt); } catch (Exception ex) { } // If we are her
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/2226633/error-sending-email-via-smtp-on-asp-net-mvc Sending email using ASP.NET I am getting this error up vote 0 down vote favorite The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. u6sm344516ibd.6 I have my code like this? MailAddress to = new MailAddress("xxxxx@gmail.com"); MailAddress from = new MailAddress("xxx@gmail.com"); MailMessage message = new MailMessage(from, to); message.Subject = http://stackoverflow.com/questions/3979368/sending-email-using-asp-net-i-am-getting-this-error "Error Occred in the application:"; message.Body = ex.Message; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); asp.net smtp gmail share|improve this question edited Oct 20 '10 at 15:18 abatishchev 57k56214353 asked Oct 20 '10 at 15:11 kumar 1,280124179 add a comment| 5 Answers 5 active oldest votes up vote 2 down vote accepted You could check if setting the EnableSsl property for SmtpClient to true and specifying the credentials would help. client.EnableSsl = true; client.Credentials = new NetworkCredential("user", "password"); share|improve this answer edited Oct 20 '10 at 15:19 abatishchev 57k56214353 answered Oct 20 '10 at 15:14 andrei m 1,0391013 its still saying the same thing? sir –kumar Oct 20 '10 at 15:20 do I need to provide Credential must and should? thanks if i use port number 467 what will happen? –kumar Oct 20 '10 at 15:28 I receive the following error if EnableSsl is set to true and credentials are not provided "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required..." –andrei m Oct 20 '10 at 15:34 Thanks Ab
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET http://www.codeproject.com/Questions/105973/Failure-sending-mail-error-in-asp-net questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / error sending Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with error sending email us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ Failure sending mail. error in asp .net Rate this: Please Sign up or sign in to vote. See more: ASP.NET Hi, I have used gmail for sending mail localy which worked fine but when i uploaded the same file on server the "Failure sending mail." error occured. Here is the code that I have written: Dim message As New MailMessage message.From = New MailAddress("xxx@gmail.com") message.To.Add(New MailAddress("xxx@yahoo.com")) message.Subject = test mail"" message.Body = "Hi you have got a test mail from me!" Dim client As New SmtpClient client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxxxxxx") client.Port = 587 client.Host = "smtp.gmail.com" client.EnableSsl = True client.Send(message) Please help me! Posted 30-Aug-10 19:47pm Sunil Tarwara232 Updated 31-Aug-10 7:45am Sandeep Mewara505.4K v3 Add a Solution Comments senguptaamlan 31-Aug-10 1:56am go through the stack trace of the error and if possible post the same here S M P 31-Aug-10 10:03am Please write your code in code block 5 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 1 Accept Solution Reject Solution If it works on your local machine and not on the server, then the server cannot access the mail server you're using, for
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. SmtpClient Class SmtpClient Methods Send Method Send Method Send Method (MailMessage) Send Method (MailMessage) Send Method (MailMessage) Send Method (MailMessage) Send Method (String, String, String, String) TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. SmtpClient.Send Method (MailMessage) .NET Framework (current version) Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 Sends the specified message to an SMTP server for delivery.Namespace: System.Net.MailAssembly: System (in System.dll)Syntax C#C++F#VB Copy public void Send( MailMessage message ) Parametersmessage Type: System.Net.Mail.MailMessageA MailMessage that contains the message to send.Exceptions Exception Condition ArgumentNullExceptionmessage is null.InvalidOperationExceptionThis SmtpClient has a SendAsync call in progress.-or- MailMessage.From is null.-or- There are no recipients specified in MailMessage.To, MailMessage.CC, and MailMessage.Bcc properties.-or- DeliveryMethod property is set to Network and Host is null.-or-DeliveryMethod property is set to Network and Host is equal to the empty string ("").-or- DeliveryMethod property is set to Network and Port is zero, a negative number, or greater than 65,535.ObjectDisposedExceptionThis object has been disposed.SmtpExceptionThe connection to the SMTP server failed.-or-Authen