Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 22nd, 2007, 07:36 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default System.Net.Mail Problem With Time Out When Sending

Hi All,



I am fairly new to programing and am having some trouble with a Windows App I'm writing to make my life a little easyer at work. If anyone here can help I would greatly appreciate it.The Idea is that I send the same emails every day with small diferences. Maybe diferent attachments, recipient, diferent appointment time, ect.. So I am writing this app in VB 2005 to make the process a little quicker. I seems to work fine so far unless I send more than one attachment. If I send more than one I get an smtp error because it times out. So I guess I need to know how to eather make my app run quicker, or adjust the timeout to give the message more time to be sent.



All sugentions are greatly apprecated. My code is below.






Imports System.Net.Mail

Public Class Form1

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

Dim strToAddress As String = txtToAddress.Text

Dim strRecName As String = txtRecName.Text

Dim strAppDate As String = DatePicker.Text

Dim strAppTime As String = TimePicker.Text

Dim strMailBody As String = ""



'Email Body Messages Messages

Dim strEmailWithAppt As String

strEmailWithAppt = "Hi " + strRecName + "," + vbNewLine

strEmailWithAppt += vbNewLine

strEmailWithAppt += " Thank you for taking the time to learn more about Radio One; " + _

"the number one Motorola distributor in Florida, and top five in the nation. " + _

"I have attached a one sheet with an overview of our company and the services we provide. " + _

"Also, some spec sheets on a couple of radios that are a good fit for your industry. " + _

"Once we get a chance to speak more I can send you more detailed information on your specific areas of interest."

strEmailWithAppt += vbNewLine

strEmailWithAppt += vbNewLine

strEmailWithAppt += "PHONE APPOINTMENT REMINDER" + vbNewLine

strEmailWithAppt += "Day: " + strAppDate + vbNewLine

strEmailWithAppt += "Time: " + strAppTime

strEmailWithAppt += vbNewLine

strEmailWithAppt += vbNewLine

strEmailWithAppt += "Best regards,"

strEmailWithAppt += vbNewLine

strEmailWithAppt += vbNewLine

strEmailWithAppt += "Adam N.Thompson" + vbNewLine

strEmailWithAppt += "Team Sales Representative" + vbNewLine

strEmailWithAppt += "Radio One" + vbNewLine

strEmailWithAppt += "Office: 407.352.9242" + vbNewLine

strEmailWithAppt += "Cell: 321.624.2721" + vbNewLine

strEmailWithAppt += "E-mail: adamt@radio1inc.com" + vbNewLine

strEmailWithAppt += "On the web: www.radio1inc.com "



Dim strEmailWithOutAppt As String

strEmailWithOutAppt = "Hi " + strRecName + "," + vbNewLine

strEmailWithOutAppt += vbNewLine

strEmailWithOutAppt += " Thank you for taking the time to learn more about Radio One; " + _

"the number one Motorola distributor in Florida, and top five in the nation. " + _

"I have attached a one sheet with an overview of our company and the services we provide. " + _

"Also, some spec sheets on a couple of radios that are a good fit for your industry. " + _

"Once we get a chance to speak more I can send you more detailed information on your specific areas of interest."

strEmailWithOutAppt += vbNewLine

strEmailWithOutAppt += vbNewLine

strEmailWithOutAppt += "Best regards,"

strEmailWithOutAppt += vbNewLine

strEmailWithOutAppt += vbNewLine

strEmailWithOutAppt += "Adam N.Thompson" + vbNewLine

strEmailWithOutAppt += "Team Sales Representative" + vbNewLine

strEmailWithOutAppt += "Radio One" + vbNewLine

strEmailWithOutAppt += "Office: 407.352.9242" + vbNewLine

strEmailWithOutAppt += "Cell: 321.624.2721" + vbNewLine

strEmailWithOutAppt += "E-mail: adamt@radio1inc.com" + vbNewLine

strEmailWithOutAppt += "On the web: www.radio1inc.com "



'Dim StrEmailSigniture As String = ""



'Attachments

Dim strBPR40 As String = "C:\Documents and Settings\Adam Thompson\Desktop\ProMo Material\Adam BPR40.pdf"

Dim strDTR As String = "C:\Documents and Settings\Adam Thompson\Desktop\ProMo Material\Adam DTR.pdf"



'create the mail message

Dim mail As New System.Net.Mail.MailMessage()

'set the addresses

mail.From = New System.Net.Mail.MailAddress("adamt@radio1inc.com")

mail.To.Add(StrToAddress)



'set the content

Try

If ckbApptYes.Checked Then

strMailBody = strEmailWithAppt

ElseIf ckbApptNo.Checked Then

strMailBody = strEmailWithOutAppt

End If

mail.Subject = "Radio One Motorola"

mail.Body = strMailBody

Catch

MessageBox.Show("Please check either email with appt, or email without appt.")

End Try



'add selected attachments from the filesystem

If ckbAttBPR40.Checked Then

mail.Attachments.Add(New System.Net.Mail.Attachment(strBPR40))

End If

If ckbAttDTR.Checked Then

mail.Attachments.Add(New System.Net.Mail.Attachment(strDTR))

End If



'send the message

Dim smtp As New System.Net.Mail.SmtpClient("smtp.emailsrvr.com")

'to change the port (default is 25), we set the port property

smtp.Port = 587

'to authenticate we set the username and password properites on the SmtpClient

smtp.Credentials = New System.Net.NetworkCredential("adamt@radio1inc.com" , "********")

smtp.Send(mail)

MessageBox.Show("Your message to '" + strToAddress + "' was sent!")

End Sub

End Class

Reply With Quote
  #2 (permalink)  
Old May 22nd, 2007, 08:21 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. Nothing seems to be out of place, I did see this line:
New System.Net.Mail.MailAddress("adamt@radio1inc.com")

which really isnt necessary as you can simply supply a string to the Mail.From and Mail.To fields. How big are the files you are attaching to the emails? If you send the same email with the same attachments from your mail client, does it send correctly?

What Mail Server are you using?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 22nd, 2007, 08:45 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response.

The attachments are just .pdf files. I can send them fine form my web mail and I'm sure any other email. I'm not sure on the mail server though. The company I work for uses an email provider. They write there webmail app in PHP so I assume it is probly on Linix or something.

One intresting thing I have found is that when I added as additional check box control for an aditional attachment I could send multiple attachments. It seems there is just one that takes too long and times out. I can use my app to send it by its self though. And I have never had a problem sending it with any other email client.

I hope this helps. This has me scratching my head for sure.

thanks.

-Adam

Reply With Quote
  #4 (permalink)  
Old May 22nd, 2007, 09:24 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm.

I don't understand this line:
One intresting thing I have found is that when I added as additional check box control for an aditional attachment I could send multiple attachments.

I don't know why an additional attachment would matter, it doesn't make sense. Unfortunately, you can not set the timeout between the server and client in code (not that I know of anyway).

By chance, is the file you are attaching and sending open inside of Acrobat in any way during the email submission? While this shouldn't matter, it is possible that Windows locks the file and is preventing the file from being attatched to the email and hence your timeout. (Just throwing things out there as I have never run into this problem)

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #5 (permalink)  
Old May 22nd, 2007, 10:05 PM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about the typo.

No PDFs open.

On the form I have check box controlls used to specify which attachments I want to send with the email. The PDFs are specsheets and promotions literiture on Motorola radios and i only attach the ones that fit the industry of the target prospect.

After my origional post I have added additional check box controls for aditional attachments. This is the code changed. I realy only added two lines.


Dim strBPR40 As String = "C:\Documents and Settings\Adam Thompson\Desktop\ProMo Material\Adam BPR40.pdf"
Dim strDTR As String = "C:\Documents and Settings\Adam Thompson\Desktop\ProMo Material\Adam DTR.pdf"
Dim strOneSheet As String = "C:\Documents and Settings\Adam Thompson\Desktop\ProMo Material\RadioOneSheet.pdf"


If ckbAttBPR40.Checked Then
mail.Attachments.Add(New System.Net.Mail.Attachment(strBPR40))
End If
If ckbAttDTR.Checked Then
mail.Attachments.Add(New System.Net.Mail.Attachment(strDTR))
End If
If ckbAttDTR.Checked Then
mail.Attachments.Add(New System.Net.Mail.Attachment(strOneSheet))
End If

What I was saying was intresting is that I can send strOneSheet, and strBP40 together without a problem, and I can send strDTR by its self. However, if I try to send strDTR with another attachment I get the exception stating that it timed out.

I notice it does take quite a bit longer to run the messageBox code at the bottom saying the email has been sent when i use the attachments. I was thinking it takes a little too long. Longer than outlook anyway. But if your saying my code looks OK I'm not sure what the problem could be.

As you said I cannot seem to find anything online showing how to adjust the Time out since its not my server.

Any ideas on anything else I could try?

Thanks again,

-Adam

Reply With Quote
  #6 (permalink)  
Old November 10th, 2012, 04:24 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Additional checkbox was the one required category you needed to incorporate.
I was also improving on a similar line of project and the clarifications here have helped me in my code too.
Also do check your smtp software and its comatibility before running a program.

------------------
bpr40
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
System.Net.Mail Problems With Sending An Email Doom C# 3 May 25th, 2008 02:49 PM
Sending mail using asp.net 2.0 Roinka ASP.NET 2.0 Basics 0 May 15th, 2006 08:22 AM
Problem in sending an e-mail via ASP.NET Rashmi_Dubey ASP.NET 2.0 Basics 2 January 28th, 2006 02:36 AM
Sending mail through VB.NET callraheel VB.NET 0 January 14th, 2005 02:15 AM
Problem with sending mail nikunjn VS.NET 2002/2003 1 January 29th, 2004 07:29 AM



All times are GMT -4. The time now is 08:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.