send mail with gmail

Discussion in 'ASP .Net' started by fredd00, Feb 18, 2008.

  1. fredd00

    fredd00 Guest

    Hi

    i'm trying to send email through my gmail account, used to work

    web.config

    <system.net>
    <mailSettings>
    <smtp from="myfrom" >
    <network defaultCredentials="true" host="smtp.gmail.com"
    port="465" userName="mygmailusername" password="mygmailpassword"/>
    </smtp>
    </mailSettings>
    </system.net>

    my fonction

    public static void SendEmail(string To, string From, string Subject,
    string Body, bool IsBodyHtml)
    {
    try
    {
    using (MailMessage message = new MailMessage(From, To,
    Subject, Body))
    {
    message.IsBodyHtml = IsBodyHtml;
    SmtpClient mailClient = new SmtpClient();
    mailClient.Send(message);
    }
    }
    catch (SmtpException ex)
    {
    throw new ApplicationException("SmtpException has
    Occured: " + ex.Message);
    }
    }

    i get either error :
    1-
    SmtpException has Occured: 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 e13sm6192679qba.37

    or
    2 - when i enable ssl
    SmtpException has Occured: The SMTP server requires a secure
    connection or the client was not authenticated. The server response
    was: 5.5.1 Authentication Required e11sm6169311qbc.5


    who can it be solved ?
    also who can i use this account to send email through the password
    recovery control ?
    thanks
     
    fredd00, Feb 18, 2008
    #1
    1. Advertising

  2. fredd00

    sloan Guest

    I have downloadable code.
    http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

    there...with gmail specific settings as well.


    Download the code. Change a couple of settings (Your username and password)
    and it should work for you.





    "fredd00" <> wrote in message
    news:...
    > Hi
    >
    > i'm trying to send email through my gmail account, used to work
    >
    > web.config
    >
    > <system.net>
    > <mailSettings>
    > <smtp from="myfrom" >
    > <network defaultCredentials="true" host="smtp.gmail.com"
    > port="465" userName="mygmailusername" password="mygmailpassword"/>
    > </smtp>
    > </mailSettings>
    > </system.net>
    >
    > my fonction
    >
    > public static void SendEmail(string To, string From, string Subject,
    > string Body, bool IsBodyHtml)
    > {
    > try
    > {
    > using (MailMessage message = new MailMessage(From, To,
    > Subject, Body))
    > {
    > message.IsBodyHtml = IsBodyHtml;
    > SmtpClient mailClient = new SmtpClient();
    > mailClient.Send(message);
    > }
    > }
    > catch (SmtpException ex)
    > {
    > throw new ApplicationException("SmtpException has
    > Occured: " + ex.Message);
    > }
    > }
    >
    > i get either error :
    > 1-
    > SmtpException has Occured: 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 e13sm6192679qba.37
    >
    > or
    > 2 - when i enable ssl
    > SmtpException has Occured: The SMTP server requires a secure
    > connection or the client was not authenticated. The server response
    > was: 5.5.1 Authentication Required e11sm6169311qbc.5
    >
    >
    > who can it be solved ?
    > also who can i use this account to send email through the password
    > recovery control ?
    > thanks
     
    sloan, Feb 18, 2008
    #2
    1. Advertising

  3. Try doing it with a chunky method:


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace PAB.SEO
    {
    public static class GmailSender
    {
    public static void SendGmail(string userName, string password,
    string mailFrom,
    string mailTo, string commaDelimCCs, string
    subject, string message, bool isBodyHtml)
    {
    System.Net.Mail.MailMessage msg = new
    System.Net.Mail.MailMessage(mailFrom, mailTo,
    subject, message);
    msg.IsBodyHtml = isBodyHtml;
    if(commaDelimCCs!="")
    msg.CC.Add(commaDelimCCs );
    System.Net.NetworkCredential cred = new
    System.Net.NetworkCredential(userName, password);
    System.Net.Mail.SmtpClient mailClient = new
    System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
    mailClient.EnableSsl = true;
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = cred;
    mailClient.Send(msg);
    }
    }
    }

    --Peter
    Site: http://www.eggheadcafe.com
    UnBlog: htp://petesbloggerama.blogspot.com
    Short Urls & more: http://ittyurl.net


    "fredd00" wrote:

    > Hi
    >
    > i'm trying to send email through my gmail account, used to work
    >
    > web.config
    >
    > <system.net>
    > <mailSettings>
    > <smtp from="myfrom" >
    > <network defaultCredentials="true" host="smtp.gmail.com"
    > port="465" userName="mygmailusername" password="mygmailpassword"/>
    > </smtp>
    > </mailSettings>
    > </system.net>
    >
    > my fonction
    >
    > public static void SendEmail(string To, string From, string Subject,
    > string Body, bool IsBodyHtml)
    > {
    > try
    > {
    > using (MailMessage message = new MailMessage(From, To,
    > Subject, Body))
    > {
    > message.IsBodyHtml = IsBodyHtml;
    > SmtpClient mailClient = new SmtpClient();
    > mailClient.Send(message);
    > }
    > }
    > catch (SmtpException ex)
    > {
    > throw new ApplicationException("SmtpException has
    > Occured: " + ex.Message);
    > }
    > }
    >
    > i get either error :
    > 1-
    > SmtpException has Occured: 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 e13sm6192679qba.37
    >
    > or
    > 2 - when i enable ssl
    > SmtpException has Occured: The SMTP server requires a secure
    > connection or the client was not authenticated. The server response
    > was: 5.5.1 Authentication Required e11sm6169311qbc.5
    >
    >
    > who can it be solved ?
    > also who can i use this account to send email through the password
    > recovery control ?
    > thanks
    >
     
    Peter Bromberg [C# MVP], Feb 18, 2008
    #3
  4. fredd00

    fredd00 Guest

    i'm still getting the error
    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 f18sm8426670qba.14

    but the emails seems to be sent anyway, i'm receiving my message


    On Feb 18, 1:31 pm, Peter Bromberg [C# MVP]
    <> wrote:
    > Try doing it with a chunky method:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Text;
    >
    > namespace PAB.SEO
    > {
    > public static class GmailSender
    > {
    > public static void SendGmail(string userName, string password,
    > string mailFrom,
    > string mailTo, string commaDelimCCs, string
    > subject, string message, bool isBodyHtml)
    > {
    > System.Net.Mail.MailMessage msg = new
    > System.Net.Mail.MailMessage(mailFrom, mailTo,
    > subject, message);
    > msg.IsBodyHtml = isBodyHtml;
    > if(commaDelimCCs!="")
    > msg.CC.Add(commaDelimCCs );
    > System.Net.NetworkCredential cred = new
    > System.Net.NetworkCredential(userName, password);
    > System.Net.Mail.SmtpClient mailClient = new
    > System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
    > mailClient.EnableSsl = true;
    > mailClient.UseDefaultCredentials = false;
    > mailClient.Credentials = cred;
    > mailClient.Send(msg);
    > }
    > }
    >
    > }
    >
    > --Peter
    > Site:http://www.eggheadcafe.com
    > UnBlog: htp://petesbloggerama.blogspot.com
    > Short Urls & more:http://ittyurl.net
    >
    > "fredd00" wrote:
    > > Hi

    >
    > > i'm trying to send email through my gmail account, used to work

    >
    > > web.config

    >
    > > <system.net>
    > > <mailSettings>
    > > <smtp from="myfrom" >
    > > <network defaultCredentials="true" host="smtp.gmail.com"
    > > port="465" userName="mygmailusername" password="mygmailpassword"/>
    > > </smtp>
    > > </mailSettings>
    > > </system.net>

    >
    > > my fonction

    >
    > > public static void SendEmail(string To, string From, string Subject,
    > > string Body, bool IsBodyHtml)
    > > {
    > > try
    > > {
    > > using (MailMessage message = new MailMessage(From, To,
    > > Subject, Body))
    > > {
    > > message.IsBodyHtml = IsBodyHtml;
    > > SmtpClient mailClient = new SmtpClient();
    > > mailClient.Send(message);
    > > }
    > > }
    > > catch (SmtpException ex)
    > > {
    > > throw new ApplicationException("SmtpException has
    > > Occured: " + ex.Message);
    > > }
    > > }

    >
    > > i get either error :
    > > 1-
    > > SmtpException has Occured: 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 e13sm6192679qba.37

    >
    > > or
    > > 2 - when i enable ssl
    > > SmtpException has Occured: The SMTP server requires a secure
    > > connection or the client was not authenticated. The server response
    > > was: 5.5.1 Authentication Required e11sm6169311qbc.5

    >
    > > who can it be solved ?
    > > also who can i use this account to send email through the password
    > > recovery control ?
    > > thanks
     
    fredd00, Feb 20, 2008
    #4
  5. fredd00

    fredd00 Guest

    it actually works fine
    the error is poped because i'm using the password recovery control,
    which doesn't seem to like my network config
    i simply cancel the event after sending the email through my email
    method

    thanks

    On Feb 18, 1:31 pm, Peter Bromberg [C# MVP]
    <> wrote:
    > Try doing it with a chunky method:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Text;
    >
    > namespace PAB.SEO
    > {
    > public static class GmailSender
    > {
    > public static void SendGmail(string userName, string password,
    > string mailFrom,
    > string mailTo, string commaDelimCCs, string
    > subject, string message, bool isBodyHtml)
    > {
    > System.Net.Mail.MailMessage msg = new
    > System.Net.Mail.MailMessage(mailFrom, mailTo,
    > subject, message);
    > msg.IsBodyHtml = isBodyHtml;
    > if(commaDelimCCs!="")
    > msg.CC.Add(commaDelimCCs );
    > System.Net.NetworkCredential cred = new
    > System.Net.NetworkCredential(userName, password);
    > System.Net.Mail.SmtpClient mailClient = new
    > System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
    > mailClient.EnableSsl = true;
    > mailClient.UseDefaultCredentials = false;
    > mailClient.Credentials = cred;
    > mailClient.Send(msg);
    > }
    > }
    >
    > }
    >
    > --Peter
    > Site:http://www.eggheadcafe.com
    > UnBlog: htp://petesbloggerama.blogspot.com
    > Short Urls & more:http://ittyurl.net
    >
    > "fredd00" wrote:
    > > Hi

    >
    > > i'm trying to send email through my gmail account, used to work

    >
    > > web.config

    >
    > > <system.net>
    > > <mailSettings>
    > > <smtp from="myfrom" >
    > > <network defaultCredentials="true" host="smtp.gmail.com"
    > > port="465" userName="mygmailusername" password="mygmailpassword"/>
    > > </smtp>
    > > </mailSettings>
    > > </system.net>

    >
    > > my fonction

    >
    > > public static void SendEmail(string To, string From, string Subject,
    > > string Body, bool IsBodyHtml)
    > > {
    > > try
    > > {
    > > using (MailMessage message = new MailMessage(From, To,
    > > Subject, Body))
    > > {
    > > message.IsBodyHtml = IsBodyHtml;
    > > SmtpClient mailClient = new SmtpClient();
    > > mailClient.Send(message);
    > > }
    > > }
    > > catch (SmtpException ex)
    > > {
    > > throw new ApplicationException("SmtpException has
    > > Occured: " + ex.Message);
    > > }
    > > }

    >
    > > i get either error :
    > > 1-
    > > SmtpException has Occured: 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 e13sm6192679qba.37

    >
    > > or
    > > 2 - when i enable ssl
    > > SmtpException has Occured: The SMTP server requires a secure
    > > connection or the client was not authenticated. The server response
    > > was: 5.5.1 Authentication Required e11sm6169311qbc.5

    >
    > > who can it be solved ?
    > > also who can i use this account to send email through the password
    > > recovery control ?
    > > thanks
     
    fredd00, Feb 20, 2008
    #5
  6. fredd00

    Guest

    On Monday, February 18, 2008 6:56:03 AM UTC+2, fredd00 wrote:
    > Hi
    >
    > i'm trying to send email through my gmail account, used to work
    >
    > web.config
    >
    > <system.net>
    > <mailSettings>
    > <smtp from="myfrom" >
    > <network defaultCredentials="true" host="smtp.gmail.com"
    > port="465" userName="mygmailusername" password="mygmailpassword"/>
    > </smtp>
    > </mailSettings>
    > </system.net>
    >
    > my fonction
    >
    > public static void SendEmail(string To, string From, string Subject,
    > string Body, bool IsBodyHtml)
    > {
    > try
    > {
    > using (MailMessage message = new MailMessage(From, To,
    > Subject, Body))
    > {
    > message.IsBodyHtml = IsBodyHtml;
    > SmtpClient mailClient = new SmtpClient();
    > mailClient.Send(message);
    > }
    > }
    > catch (SmtpException ex)
    > {
    > throw new ApplicationException("SmtpException has
    > Occured: " + ex.Message);
    > }
    > }
    >
    > i get either error :
    > 1-
    > SmtpException has Occured: 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 e13sm6192679qba.37
    >
    > or
    > 2 - when i enable ssl
    > SmtpException has Occured: The SMTP server requires a secure
    > connection or the client was not authenticated. The server response
    > was: 5.5.1 Authentication Required e11sm6169311qbc.5
    >
    >
    > who can it be solved ?
    > also who can i use this account to send email through the password
    > recovery control ?
    > thanks
     
    , Aug 5, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg
    Replies:
    1
    Views:
    2,631
    =?Utf-8?B?U2l2YSBN?=
    Sep 19, 2005
  2. Nathan Sokalski
    Replies:
    3
    Views:
    1,951
    Larry Lard
    Nov 23, 2005
  3. =?Utf-8?B?Unlhbg==?=
    Replies:
    2
    Views:
    3,910
    Steven Cheng[MSFT]
    Feb 28, 2006
  4. Replies:
    15
    Views:
    155,994
    abhishek-technicalwork
    Jul 11, 2012
  5. Brian Rhiel
    Replies:
    1
    Views:
    190
    Hassan Schroeder
    May 31, 2010
Loading...

Share This Page