Hi,

I'm trying to send an e-mail from a managed application.

I found the following example:

MailAddress ^From = gcnew MailAddress("xxx@zzz.com");
    MailAddress ^To   = gcnew MailAddress("ttt@zzz.com");
    
    MailMessage ^message = gcnew MailMessage(From, To);
    message->Subject = "Testing sending mail";
    message->Body = "Body of message";
    SmtpClient^ client = gcnew SmtpClient( "smtp.foo.com" );
    client->Credentials = CredentialCache::DefaultNetworkCredentials;
    
    
    client->Send( message );
    client->~SmtpClient();

I don't know how to set the DefaultNetworkCredentials in fact.

What I have for authentification is a a login name and a password for the SMTP server.

How do I use them?

Try substituting these in for line 8. You were trying to pass it into client as static which might work but this way you get all the proper info in there. I tested it, it works.

CredentialCache ^ mycreds = gcnew CredentialCache();
	mycreds->DefaultNetworkCredentials->UserName = "bob";
	mycreds->DefaultNetworkCredentials->Password = "bob";
	
	client->Credentials = mycreds;

Try substituting these in for line 8. You were trying to pass it into client as static which might work but this way you get all the proper info in there. I tested it, it works.

CredentialCache ^ mycreds = gcnew CredentialCache();
	mycreds->DefaultNetworkCredentials->UserName = "bob";
	mycreds->DefaultNetworkCredentials->Password = "bob";
	
	client->Credentials = mycreds;

Thanks, that seems to be what I need.

However, when I send the mail, I get:

System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.0 Need to authenticate via SMTP-AUTH-Login

How do I change the method to SMTP-AUTH?

I'm not sure what the problem is... I sent via ISP's SMTP server to gmail and it worked. A couple of possibilities I ran across:
Try changing client->Port to 587.
-or-
Make sure you're running as admin so that you have the right privileges to send email.

There may be a few other settings you can play with. You could try asking your ISP/server admin for details...

ITry changing client->Port to 587.[/URL]
-or-
Make sure you're running as admin so that you have the right privileges to send email.

Unfortunately, that did not help.

I was trying with a GMX account. With GMAIL, I get a different message:

]The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

There may be a few other settings you can play with. You could try asking your ISP/server admin for details...

I have no idea what are these settings!

Thanks.

You got me. It did seem like people were having problems sending from gmail. I only sent to gmail not from it.

By other settings I mean the members of SmtpClient.

I'm afraid I don't know much more than this about these types of systems.

Y
By other settings I mean the members of SmtpClient.

I already looked into these, without success.

Thanks for trying, maybe somebody else will have an idea.

By other settings I mean the members of SmtpClient.

By following your link, I stumbled on the following code:

client->Credentials = gcnew NetworkCredential("username", "password");

and that worked!

Thanks.

Super! I was going to suggest that at one point but I thought it was redundant. Oh well. Glad it worked out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.