Hi,
I am trying to send mail via gmail from an ASP.NET app. It seems like this 
should be easy, and many code snippets on the web show how to do it.  
However, I cannot get it to work.  When I use port 465, I get a timeout 
exception. When I use port 587, I get an "Authentication Required 
exception".  Here is my code.  I have tried all sorts of variations on the 
syntax, but to no avail:
 
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
client.EnableSsl = true;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("
[email protected]", "password");
client.Credentials = cred;  // null if assign Credentials in one line of 
code
client.UseDefaultCredentials = false;
client.Timeout = 5000;
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add("[email protected]");
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Subject = "The Subject";
message.Body = "this is the body";
try
{
  client.Send(message);
}
catch (Exception ex) { //  do something }
Here is the matching code from web.config. This may be redundant, but it 
doesn't seem to matter if I set the port & credentials here or in C#.
 
<system.net>
  <mailSettings>
    <smtp from="[email protected]">
    <network host="smtp.gmail.com" userName="[email protected]" 
password="password"  />
    </smtp>
  </mailSettings>
</system.net>
 
I am quite sure my actual username and password are correct because I can 
manually log into gmail using those credentials.  
 
Help!  I am stuck here.
 
Thanks.
 
Dan
 

-- 
You received this message because you are subscribed to the Google Groups 
"Google Apps Domain Information and Management APIs" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-apps-mgmt-apis/-/NIkmC_yOvyAJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-apps-mgmt-apis?hl=en.

Reply via email to