Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:22:07+00:00 2026-06-15T02:22:07+00:00

I am trying to implement a forgot password method into my site. It works

  • 0

I am trying to implement a “forgot password” method into my site. It works perfectly in debug. Using the same code and db, but published to our web server it fails when it tries to send the message.

The error that I get is:

There was an error sending you an email.
The specified string is not in the form required for an e-mail address.

The email is valid, so I have no idea why it is failing.

Because it is a live environment I cannot step through the code to see exactly where and why it is failing. I implemented db logging so I can see how far it gets before it fails and it successfully executes all code up to this point:

 var smtp = new SmtpClient
 {
     Host = host,
     Port = port,
     EnableSsl = ssl,
     DeliveryMethod = SmtpDeliveryMethod.Network,
     UseDefaultCredentials = false,
     Credentials = new NetworkCredential(fromAddress.Address, fromPw)
 };
 using (var message = new MailMessage()
 {
     Subject = subject,
     Body = body,
     IsBodyHtml = ishtml,
     From = fromAddress
 })

 {
     foreach (MailAddress t in toCol)
     { message.To.Add(t); }
     foreach (MailAddress c in ccCol)
     { message.CC.Add(c); }
     foreach (MailAddress b in bccCol)
     { message.Bcc.Add(b); }
     smtp.Send(message);
 }

It never gets to the next db logging so it has to be failing here. In my test I have exactly one email address for the to and none for bcc and cc. When stepping through in debug it correctly loads the single email address and doesn’t load any for cc and bcc. I have no idea what it is considering to be an invalid email address.

EDIT:

We use Google Apps as our mail server so both my workstation and the server have to connect. I am using the following:

  • Host: smtp.gmail.com
  • Port: 587
  • EnableSsl: true
  • Credentials: valid username and password that work in debug

EDIT 2:
To incorporate some of the suggestions from you.
The fromAddress is set earlier using values from the db like this:

DataTable ts = DAL.Notification.GetNotificationSettings();
var fromEmail = ts.Rows[0]["fromadr"].ToString().Trim();
var fromName = ts.Rows[0]["fromname"].ToString().Trim();
var host = ts.Rows[0]["server"].ToString().Trim();
var port = Convert.ToInt32(ts.Rows[0]["smtpport"]);
var ssl = Convert.ToBoolean(ts.Rows[0]["is_ssl"]);
var ishtml = Convert.ToBoolean(ts.Rows[0]["is_html"]);
var bodyTemplate = ts.Rows[0]["bodyTemplate"].ToString();
body = bodyTemplate.Replace("{CONTENT}", body).Replace("{emailFooter}","");// Needs to use the Global emailFooter resource string

var fromAddress = new MailAddress(fromEmail, fromName);

I have even tried hard coding the from address like this:

message.From = new MailAddress("websystem@mydomain.com");

I still get the error and it still fails when defining the message.

Any other suggestions on how to find and fix the problem?

ANSWER

I did not define the default from address in the web.config like this:

    <system.net>
     <mailSettings>
       <smtp from="email@yourdomain.com">
         <network host="smtp.yourdomain.com"/>
       </smtp>
     </mailSettings>   </system.net>

So it failed at var message = new MailMessage() before I could define the correct from address.

I either needed to implement var message = new MailMessage(From,To) or provide a default from address in web.config (which is what I did)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:22:08+00:00Added an answer on June 15, 2026 at 2:22 am

    This error can be caused by two things:

    1. One of the email addresses your using (for message.To, message.CC or message.Bcc) is invalid, i.e. it doesn’t follow the required format of someuser@somedomain.xxx.

    2. The From address configured in Web.Config is invalid:

      <system.net>
        <mailSettings>
          <smtp from="invalid@@email">
            <network host="smtp.gmail.com"/>
          </smtp>
        </mailSettings>
      </system.net>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement 'forgot password' functionality using JSF SEAM in our index
I'm trying to implement method Find that searches the database. I forgot to mention
I'm trying to implement a password forgot page in my website. I just would
Trying to implement the new FP 10.1 Global error handler into my projects but
I am trying implement a most recent widget into my tumblr post. So far,
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
I'm trying to implement a fire-and-forget class method similar to + (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue
I'm trying to implement my own websocket server and am running into a bit
I'm trying to implement fire and forget functionality, using the Task Parallel Library. With
trying to implement the following but its not working <script> function loadmap(lat,lng) { //alert(lat,lang);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.