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:
[email protected]" + 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:
[email protected]" + 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("
[email protected]")
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("
[email protected]" , "********")
smtp.Send(mail)
MessageBox.Show("Your message to '" + strToAddress + "' was sent!")
End Sub
End Class