Results 1 to 7 of 7

Thread: [2008] SMTP MailMessage Freezes My PC

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Exclamation [2008] SMTP MailMessage Freezes My PC

    Hi,
    I'm using the below code to send mail with attachment, its working fine except that my PC freezes for 10 seconds whenever I run this code, is there a way to avoid system lag?,
    I tried to lower the process priority by using "Process.GetCurrentProcess.PriorityClass = ProcessPriorityClass.Idle" but it didn't help.

    Any suggestions please?
    Code:
    Dim MyMailMessage As New MailMessage
    
            Try
                MyMailMessage.From = New MailAddress("[email protected]")
                MyMailMessage.To.Add("[email protected]")
                MyMailMessage.Subject = "Mail Subject...."
                Dim attch As New Mail.Attachment("C:\Picture.jpeg")
                MyMailMessage.Attachments.Add(attch)
                MyMailMessage.Body = "Message text...."
                Dim SMTP As New SmtpClient("smtp.gmail.com")
                SMTP.Port = 587
                SMTP.EnableSsl = True
                SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "myemailpassword")
                SMTP.Send(MyMailMessage)
                
            Catch ex As Exception
    
            End Try

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2008] SMTP MailMessage Freezes My PC

    Hmmmnnn... Probably using a Backgroundworker to do the sending?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] SMTP MailMessage Freezes My PC

    Are you saying that your whole system becomes unresponsive for 10 seconds or just your application? What happens if you send the same e-mail from your default e-mail client?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] SMTP MailMessage Freezes My PC

    My whole system freezes when using the above code, I tried sending the same email via outlook and it went through without problems!

  5. #5
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: [2008] SMTP MailMessage Freezes My PC

    Is Outlook set up to use port 587 for SMTP as well?

    Maybe it is set to use port number 25 which is the default.

    Set the port to 25 in your code and see if it works.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] SMTP MailMessage Freezes My PC

    Hey,

    How big is the attachment that you are trying to add to the email?

    You might want to look into the SmtpClients SendAsync method.

    http://msdn.microsoft.com/en-us/library/x5x13z6h.aspx

    You might have some luck with this.

    Hope this helps.

    Gary

  7. #7
    New Member
    Join Date
    Jan 2009
    Posts
    8

    Re: [2008] SMTP MailMessage Freezes My PC

    Use SMTPClient.SendAsync for a non-blocking operation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width