Sending email via the port 465 of Gmail don't work! I don't know if there are bugs in .NET.

I use the following code to send  email via  Gmail , it works well when I use client.Port = 587, but it doesn't work if I use client.Port = 465 !  but If I use email client software such as Outlook Express with port 465, it woks well, I don't know if there are bugs in .NET.


    protected void btnSend_Click(object sender, EventArgs e)
    {
        //Add Async="true" to .ASPX page

        SmtpClient client=new SmtpClient();
        client.EnableSsl = true;
        client.Credentials = new System.Net.NetworkCredential("my@gmail.com", "***");
        client.Host = "smtp.gmail.com";
        client.Port = 587;// client.Port = 465 don't work! 


        SendEmail("my@gmail.com", "To@Yahoo.com", "Subject 587", "Body 587", false, null, client);
    }

 

    /***************************** Send Email***********************/
    #region Send  Email

    public static void SendEmail(
                    string From,
                    string To,
                    string Subject,
                    string Body,
                    bool IsBodyHtml,
                    string Attachment,
                    SmtpClient client)
    {
        if (IsValidEmail(From) && IsValidEmail(To))
        {
            DelegateSendEmail myDelegateSendEmail = new DelegateSendEmail(SyncSendEmail);
            myDelegateSendEmail.BeginInvoke(From, To, Subject, Body, IsBodyHtml, Attachment, client, null, null);
        }
    }


    private delegate void DelegateSendEmail(
                    string From,
                    string To,
                    string Subject,
                    string Body,
                    bool IsBodyHtml,
                    string Attachment,
                    SmtpClient client);


    private static void SyncSendEmail(
                    string From,
                    string To,
                    string Subject,
                    string Body,
                    bool IsBodyHtml,
                    string Attachment,
                    SmtpClient client)
    {
       
        MailMessage message = new MailMessage(new MailAddress(From), new MailAddress(To));
        message.Subject = Subject;
        message.Body = Body;
        message.IsBodyHtml = IsBodyHtml;
        if (!string.IsNullOrEmpty(Attachment))
        {
            message.Attachments.Add(new Attachment(Attachment));
        }

        client.SendCompleted += new SendCompletedEventHandler(SmtpClient_OnCompleted);

        try
        {
            client.SendAsync(message, message);
        }
        catch
        {
        }
    }


    private static void SmtpClient_OnCompleted(object sender, AsyncCompletedEventArgs e)
    {

    }

    private static bool IsValidEmail(string strIn)
    {
        if (string.IsNullOrEmpty(strIn))
        {
            return false;
        }
        else
        {
            return Regex.IsMatch(strIn, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
        }
    }

    #endregion
    /***************************** Send Email***********************/

 


SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files

SuperCool Random Number Generator
0
mycwcgr
12/10/2008 11:01:16 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

6 Replies
1361 Views

Similar Articles

[PageSpeed] 4

 I don't think this is a problem w/ .NET.  It could be that your network is blocking connection to port 465.  What error are you getting?

If you have access to the server, I would try telnet to smtp.gmail.com over port 465.


Bruce
DiscountASP.NET: Developer Ready ASP.NET Web Hosting
- Microsoft Gold Certified Partner
- Voted 2008, 2007, 2006 & 2005 Best ASP.NET Web Hosting by asp.netPRO Magazine
0
Bruce
12/11/2008 1:09:37 AM

itrs not probblem with .net in the web.config file add mail settings or in the appsettings

add the smtpserver and value

and check the relay address in the IIS Settings.

0
krishnada25
12/11/2008 2:08:25 AM

 I dont know how you made your outlook work with 465 because it clearly does not work for me. And also the port or GMAIL is 587. SO naturally it will work for 587.

http://mail.google.com/support/bin/answer.py?answer=86375


Shoban Kumar
http://www.crankup.net :: My tech blog
http://www.codegeeks.net :: my code blog
0
shobankr
12/11/2008 2:15:47 AM

 Why would you be using port 465? Google REQUIRES you to use port 587 with a secure connection. That's google's setting and is not up to you, .net, outlook or whatever else. Google will only accept SMTP requests via port 587 over a secure connection.

0
HeartattacK
12/11/2008 3:10:43 AM

From http://mail.google.com/support/bin/answer.py?hl=en&answer=13287  I get the information I can user either port 465 or port 587 !

When I use the code above to send email with the port 465, I don't get any error information, it's seems the email  disappear :(


SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files

SuperCool Random Number Generator
0
mycwcgr
12/12/2008 12:59:44 AM
Reply:

Similar Artilces:

Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I?
Name: Ed Leech Email: ELCraftatzoominternetdotnet Product: Thunderbird Summary: Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I? Comments: I am getting frusted with all the emails coming in that I do not want, I am using the tools to get thme out but they keep coming. They just use different names or whatever. I have been thinking of just switching to something else but my business intrusts know this email and it is tooo confusing to change. Every time I go out of town on bu...

I don't know why my code don't work(it's for shopping cart)
I wrote this code for shopping cart.I used c lass for it and i want to store orders in cache.the customer username is in a session.customer select the product from a datalist.but and I want to show the orders in gridview .but when I select some product and go to the page that gridview is in it (shopping cart page)I could,t see any thing.please look at my code and see if I wrote my code incorrect.thanks for your helping me.-------------------------------------------------------------------------  //the code for add product to shopping cart(products are in data list)protected void order(o...

cpan>install NET::SSH ----> Can't install NET::SSH don't know what it is?
Good day! This is the first time I'll be using the cpan to install modules. I run: perl -MCPAN -e shell and answer the questions one by one. When its done, I issued install NET::SSH at the cpan> prompt and I got the message: Can't install NET::SSH Don't know what it is. Question: How will I make cpan> know what NET::SSH is? Is there something I have to update first? How can I search for some useful modules using cpan> rather than using cpan search in www.cpan.org? What is auto bundle? And what does 'cpan -a' does? When I ran it, I can some...

superreview requested: [Bug 264442] plugin finder can't find anything for windows media. : [Attachment 162212] Don't assume we don't have a plugin before getting a responce from the network.
Johnny Stenback <jst@mozilla.jstenback.com> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 264442: plugin finder can't find anything for windows media. https://bugzilla.mozilla.org/show_bug.cgi?id=264442 Attachment 162212: Don't assume we don't have a plugin before getting a responce from the network. https://bugzilla.mozilla.org/attachment.cgi?id=162212&action=edit ...

superreview granted: [Bug 264442] plugin finder can't find anything for windows media. : [Attachment 162212] Don't assume we don't have a plugin before getting a responce from the network.
Boris Zbarsky <bzbarsky@mit.edu> has granted Johnny Stenback <jst@mozilla.jstenback.com>'s request for superreview: Bug 264442: plugin finder can't find anything for windows media. https://bugzilla.mozilla.org/show_bug.cgi?id=264442 Attachment 162212: Don't assume we don't have a plugin before getting a responce from the network. https://bugzilla.mozilla.org/attachment.cgi?id=162212&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> r+sr=bzbarsky, I guess.. Is ther a reason mIsBrokenPlugin is write-only? ...

superreview granted: [Bug 340083] Crash [@ nsSVGPathGeometryFrame::GetCanvasTM] with image in title in defs : [Attachment 224205] don't create frames for content we don't handle, don't invalidate nond
Robert O'Callahan (Novell) <roc@ocallahan.org> has granted superreview: Bug 340083: Crash [@ nsSVGPathGeometryFrame::GetCanvasTM] with image in title in defs https://bugzilla.mozilla.org/show_bug.cgi?id=340083 Attachment 224205: don't create frames for content we don't handle, don't invalidate nondisplay content https://bugzilla.mozilla.org/attachment.cgi?id=224205&action=edit ...

superreview granted: [Bug 245619] Don't bother converting result of scripts into a string when the caller doesn't care about the value. : [Attachment 150056] Don't convert the result to a string if t
Brendan Eich <brendan@mozilla.org> has granted Johnny Stenback <jst@mozilla.jstenback.com>'s request for superreview: Bug 245619: Don't bother converting result of scripts into a string when the caller doesn't care about the value. http://bugzilla.mozilla.org/show_bug.cgi?id=245619 Attachment 150056: Don't convert the result to a string if the caller doesn't care about the return value. http://bugzilla.mozilla.org/attachment.cgi?id=150056&action=edit ------- Additional Comments from Brendan Eich <brendan@mozilla.org> Duh, thanks. r+sr=me....

superreview requested: [Bug 245619] Don't bother converting result of scripts into a string when the caller doesn't care about the value. : [Attachment 150056] Don't convert the result to a string if
Johnny Stenback <jst@mozilla.jstenback.com> has asked Brendan Eich <brendan@mozilla.org> for superreview: Bug 245619: Don't bother converting result of scripts into a string when the caller doesn't care about the value. http://bugzilla.mozilla.org/show_bug.cgi?id=245619 Attachment 150056: Don't convert the result to a string if the caller doesn't care about the return value. http://bugzilla.mozilla.org/attachment.cgi?id=150056&action=edit ...

Flash don't show up/youtube don't work
Name: Alexandre Torres Product: Minefield Summary: Flash don't show up/youtube don't work Comments: I'm using the windows 64 bits version of firefox 3, and flash plugin don't seem to work...even restarting firefox. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.2 x64; en-US; rv:1.9a1) Gecko/20061007 Minefield/3.0a1 ...

superreview requested: [Bug 217896] ASSERTION: nsMemoryImpl::Alloc of 0: 'size' in GlobalWindowImpl::Unescape : [Attachment 130691] don't do silly things that don't make sense
timeless@myrealbox.com <timeless@bemail.org> has asked Johnny Stenback <jst@netscape.com> for superreview: Bug 217896: ASSERTION: nsMemoryImpl::Alloc of 0: 'size' in GlobalWindowImpl::Unescape http://bugzilla.mozilla.org/show_bug.cgi?id=217896 Attachment 130691: don't do silly things that don't make sense http://bugzilla.mozilla.org/attachment.cgi?id=130691&action=edit ...

superreview granted: [Bug 217896] ASSERTION: nsMemoryImpl::Alloc of 0: 'size' in GlobalWindowImpl::Unescape : [Attachment 130691] don't do silly things that don't make sense
Johnny Stenback <jst@netscape.com> has granted timeless@myrealbox.com <timeless@bemail.org>'s request for superreview: Bug 217896: ASSERTION: nsMemoryImpl::Alloc of 0: 'size' in GlobalWindowImpl::Unescape http://bugzilla.mozilla.org/show_bug.cgi?id=217896 Attachment 130691: don't do silly things that don't make sense http://bugzilla.mozilla.org/attachment.cgi?id=130691&action=edit ------- Additional Comments from Johnny Stenback <jst@netscape.com> sr=jst ...

superreview requested: [Bug 252984] Cannot type in any of the fields
Aaron Leventhal <aaronleventhal@moonset.net> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 252984: Cannot type in any of the fields - forms don't get focus on left-click http://bugzilla.mozilla.org/show_bug.cgi?id=252984 Attachment 154483: We actually don't need either nsIFrame::FocusableAncestor() or nsGenericHTMLElement::HandleDOMEvent() anymore http://bugzilla.mozilla.org/attachment.cgi?id=154483&action=edit ...

superreview granted: [Bug 252984] Cannot type in any of the fields
Boris Zbarsky <bzbarsky@mit.edu> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 252984: Cannot type in any of the fields - forms don't get focus on left-click http://bugzilla.mozilla.org/show_bug.cgi?id=252984 Attachment 154483: We actually don't need either nsIFrame::FocusableAncestor() or nsGenericHTMLElement::HandleDOMEvent() anymore http://bugzilla.mozilla.org/attachment.cgi?id=154483&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> If things still work right and someone who...

WindowsApplication can send email,but WebApplication can't send,and don't show error.
WindowsApplication can send email,but WebApplication can't send,and don't show error. this is code Dim strBody As String = "This is the body..." Dim OLApp As New outlook.Application() Dim msg As outlook.MailItem msg = OLApp.CreateItem(outlook.OlItemType.olMailItem) msg.To = "sbzhong@cclmotors.com" msg.Subject = "Automated e-mail" msg.Body = strBody CType(msg, outlook._MailItem).Send() ...

Web resources about - Sending email via the port 465 of Gmail don't work! I don't know if there are bugs in .NET. - asp.net.getting-started

Resources last updated: 2/6/2016 6:51:32 PM