0 votes

Hi,

the exchange server im trying to connect with Smtp to send a mail fails with "'test-user' is not a valid email address. Parametername: address"

Why i cannot use simple usernames? Our usernames are NOT email addresses.

Code snippet i use:

// creds is a string array in this case {[AUTHTYPE], [USERNAME], [PASSWORD], [SERVERNAME_EXCHANGE]}
// in this example creds={"Normal", "test-user", "abc123def", "mailhost.mydomain.com"}
using (Smtp client = new Smtp())
{
     string server = creds[3];
     try
     {
         client.ConnectSSL(server);
     }
     catch
     {
         client.Connect(server);
         client.StartTLS();
     }
     if (creds[0] == "OAuth2")  // remove if authentication is not needed
     {
         client.LoginOAUTH2(creds[1], creds[2]);
     }
     else
     {
         client.UseBestLogin(creds[1], creds[2]);
     }
     ...
by (200 points)
edited by
Can you please post a code snipped you are using? I don't think that UseBestLogin has any kind of restrictions on login paramter.
added my code snippet in my main post
What is the exception StackTrace and Type?
i think i got it. The sender setting using "new MailBox" and using the username as sender mail was the issue and that was before the code snippet i pasted. my fault. just for your info, the error message pops up if you create a new MailBox with invalid email address. Makes sense.

1 Answer

0 votes

Smtp.UseBestLogin has no restrictions on 'user' parameter.

I assume the exception comes from MailBox class, when you instantiate From email address. Form must be a valid email, otherwise your email message is going to violate the RFC standard.

You can force Mail.dll to ignore this restriction by using MailBox.CreateWithoutValidation method instead of constructor.

Again, this is only a assumption, exception's StackTrace and Type would help to be certain.

by (297k points)
...