Sending Mail from asp.net for Gmail ID

Discussion in 'ASP .Net' started by jack, Nov 24, 2007.

  1. jack

    jack Guest

    Hi,
    Im trying to send mail from asp.net page to gmail account.
    Im trying to do this with the help of below code, but cant archive
    it.



    MailMessage message = new MailMessage("", "",
    "", "");
    SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    smtp.Send(message);



    The above code doesn't seem to work..

    Please help
     
    jack, Nov 24, 2007
    #1
    1. Advertising

  2. jack

    Newbie Coder Guest

    Jack,

    Ports 465/995 are secure in Gmail. There is a free SSL library which Gmail use for their
    Gmail e-mail tool. See below:

    http://www.mentalis.org/soft/projects/ssocket/

    --
    Newbie Coder
    (It's just a name)


    "jack" <> wrote in message
    news:...
    > Hi,
    > Im trying to send mail from asp.net page to gmail account.
    > Im trying to do this with the help of below code, but cant archive
    > it.
    >
    >
    >
    > MailMessage message = new MailMessage("", "",
    > "", "");
    > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > smtp.Send(message);
    >
    >
    >
    > The above code doesn't seem to work..
    >
    > Please help
     
    Newbie Coder, Nov 24, 2007
    #2
    1. Advertising

  3. "jack" <> wrote in message
    news:...

    > Im trying to send mail from asp.net page to gmail account.
    > Im trying to do this with the help of below code, but cant archive
    > it.
    > MailMessage message = new MailMessage("", "",
    > "", "");
    > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > smtp.Send(message);
    >
    > The above code doesn't seem to work..


    There are several things here:

    1) You don't need to use GMail as the relay server just because you want to
    send email *to* a Gmail account...

    2) What you mean by "can't archive it"? What archive are you talking
    about...?

    3) The MailMessage() object declaration is incorrect:
    http://www.systemnetmail.com/faq/3.1.1.aspx


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Nov 24, 2007
    #3
  4. Here is sample working Gmail Sender code. Watch carefully at everything that
    is done:

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

    namespace PAB.Utils
    {
    public static class Sender
    {
    public static void SendGmail(string userName, string password,
    string mailFrom,
    string mailTo,string subject, string
    message,bool isBodyHtml)
    {
    System.Net.Mail.MailMessage msg = new
    System.Net.Mail.MailMessage(mailFrom,mailTo,
    subject, message);
    msg.IsBodyHtml = isBodyHtml;
    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
    "Inside every large program, there is a small program trying to get out."
    http://www.eggheadcafe.com
    http://petesbloggerama.blogspot.com
    http://www.blogmetafinder.com



    "jack" wrote:

    > Hi,
    > Im trying to send mail from asp.net page to gmail account.
    > Im trying to do this with the help of below code, but cant archive
    > it.
    >
    >
    >
    > MailMessage message = new MailMessage("", "",
    > "", "");
    > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > smtp.Send(message);
    >
    >
    >
    > The above code doesn't seem to work..
    >
    > Please help
    >
     
    Peter Bromberg [C# MVP], Nov 24, 2007
    #4
  5. jack

    Henk Kelder Guest

    You should not send your message to gmail directly.

    Instead, use the SMTP server that belongs to your domain/internet provider.





    "jack" <> wrote in message
    news:...
    > Hi,
    > Im trying to send mail from asp.net page to gmail account.
    > Im trying to do this with the help of below code, but cant archive
    > it.
    >
    >
    >
    > MailMessage message = new MailMessage("", "",
    > "", "");
    > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > smtp.Send(message);
    >
    >
    >
    > The above code doesn't seem to work..
    >
    > Please help
     
    Henk Kelder, Nov 25, 2007
    #5
  6. jack

    sloan Guest

    I have a gmail example wired up (downloadable code) at:
    http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry




    "jack" <> wrote in message
    news:...
    > Hi,
    > Im trying to send mail from asp.net page to gmail account.
    > Im trying to do this with the help of below code, but cant archive
    > it.
    >
    >
    >
    > MailMessage message = new MailMessage("", "",
    > "", "");
    > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > smtp.Send(message);
    >
    >
    >
    > The above code doesn't seem to work..
    >
    > Please help
     
    sloan, Nov 25, 2007
    #6
  7. jack

    jack Guest

    Thanks all it worked

    have created a small application which sends the mail.
     
    jack, Nov 27, 2007
    #7
  8. jack

    shobaguna Guest

    "Peter Bromberg [C# MVP]" wrote:

    > Here is sample working Gmail Sender code. Watch carefully at everything that
    > is done:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Text;
    >
    > namespace PAB.Utils
    > {
    > public static class Sender
    > {
    > public static void SendGmail(string userName, string password,
    > string mailFrom,
    > string mailTo,string subject, string
    > message,bool isBodyHtml)
    > {
    > System.Net.Mail.MailMessage msg = new
    > System.Net.Mail.MailMessage(mailFrom,mailTo,
    > subject, message);
    > msg.IsBodyHtml = isBodyHtml;
    > 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
    > "Inside every large program, there is a small program trying to get out."
    > http://www.eggheadcafe.com
    > http://petesbloggerama.blogspot.com
    > http://www.blogmetafinder.com
    >
    >
    >
    > "jack" wrote:
    >
    > > Hi,
    > > Im trying to send mail from asp.net page to gmail account.
    > > Im trying to do this with the help of below code, but cant archive
    > > it.
    > >
    > >
    > >
    > > MailMessage message = new MailMessage("", "",
    > > "", "");
    > > SmtpClient smtp = new SmtpClient("smtp.gmail.com",465);
    > > smtp.Send(message);
    > >
    > >
    > >
    > > The above code doesn't seem to work..
    > >
    > > Please help
    > >
     
    shobaguna, Feb 8, 2008
    #8
  9. jack

    shobaguna Guest

    i want to send a msge to

    "jack" wrote:

    > Thanks all it worked
    >
    > have created a small application which sends the mail.
    >
    >
     
    shobaguna, Feb 8, 2008
    #9
  10. I want a lot of thing but I do not post them all here :)

    If you have a question then ask and do not forget to provide specific
    problem you face with descriptive error you get (if any)

    George.


    "shobaguna" <> wrote in message
    news:...
    >i want to send a msge to
    >
    > "jack" wrote:
    >
    >> Thanks all it worked
    >>
    >> have created a small application which sends the mail.
    >>
    >>
     
    George Ter-Saakov, Feb 8, 2008
    #10
    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,627
    =?Utf-8?B?U2l2YSBN?=
    Sep 19, 2005
  2. Replies:
    4
    Views:
    55,489
  3. Replies:
    0
    Views:
    1,375
  4. MMAS
    Replies:
    4
    Views:
    1,463
    Bruno Alexandre
    Oct 19, 2006
  5. Mikael H.
    Replies:
    1
    Views:
    226
    Robert Klemme
    Feb 21, 2011
Loading...

Share This Page