Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send e-mail 1

Status
Not open for further replies.

yosie2007

Technical User
Jun 23, 2007
46
US
objEmail.To.Add("Letting1@yahoo.com"; "letting2@hotmail.com")

I try to send e-mail to more than one person like I did below and I am getting an error ....I know I could do this but I do not want to use CC

objEmail.CC.Add("letting2@hotmail.com")


 
Imports System.Net.Mail

Private Sub SendMail()
Dim fromEmail As String = txtEmail.Text
Dim objEmail As New MailMessage
objEmail.To.Add("letting1@yahoo.com")
objEmail.CC.Add("Yosef.teferi@yahoo.com")
objEmail.CC.Add("letting2@hotmail.com")
objEmail.From = New MailAddress(fromEmail)
Dim sMsg As String
Dim rcvdEmail As String = fromEmail
'If rcvdEmail = "Bid.Letting@dot.state.mn.us" Then
sMsg = "Your order has been recieved." & vbCrLf & "The results are as follows:" & vbCrLf
sMsg += "S.P. Number :" & lblSpId.Text & vbCrLf
sMsg += "Office : " & txtOffice.Text & vbCrLf
sMsg += "Vendor Name : " & txtVendor.Text & vbCrLf
sMsg += "Contact Person : " & txtPerson.Text & vbCrLf
sMsg += "Address 1 : " & txtAddress1.Text & vbCrLf
sMsg += "Address 2 : " & txtAddress2.Text & vbCrLf
sMsg += "City : " & txtCity.Text & vbCrLf
sMsg += "Zip Code : " & txtZip.Text & vbCrLf
sMsg += "E-mail Address : " & txtEmail.Text & vbCrLf
sMsg += "Phone Number : " & txtPhone.Text & vbCrLf
sMsg += "Fax Number : " & txtFax.Text & vbCrLf
sMsg += "Comments : " & txtComment.Text & vbCrLf


sMsg += "Number of Plans Ordered : " & txtPlans.Text & vbCrLf
sMsg += "Number of Proposals Ordered : " & txtProposals.Text & vbCrLf
sMsg += "Number of CD Version Ordered : " & txtCD.Text & vbCrLf
' sMsg += "Here is my Suggestions / Comments : " & txtSummary.Text & vbCrLf
objEmail.Subject = "Plan proposal order"
' objEmail.Attachments.Add(New Attachment(AttachementFile.PostedFile.InputStream, AttachementFile.FileName))
objEmail.Body = sMsg
objEmail.IsBodyHtml = False
'Else
' sMsg = "Hello, this is an automated message to let" & vbCrLf
' sMsg += "you know that your Order has been received." & vbCrLf
' sMsg += "We will take aproperiate action and respond to you soon as possible." & vbCrLf
' sMsg += "Thank you," & vbCrLf
' sMsg += "Plan Room"
' objEmail.Subject = "Plan proposal order"
' objEmail.Body = sMsg
'End If
Dim SmtpMail As New SmtpClient()
SmtpMail.Send(objEmail)
Response.Redirect("thankyou.aspx")

End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
SendMail()
End Sub

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Response.Redirect("plans.aspx")
End Sub
 
you need to add email addresses one at a time
Code:
objEmail.To.Add("Letting1@yahoo.com")
objEmail.To.Add("letting2@hotmail.com")

I would recommend handeling the body differently as well.
either load a text file and replace strings, use XML/XLST, or use a System.Text.StringBuilder object.
[tt]string x += ... [/tt]uses alot of resources that are not necessary.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
If you know all the email addresses ahead of time (as well as subject, body, from address - which it looks like you do in this case) there is also an overloaded constructor you can use to create your MailMessage object. It takes a comma separated string of email addresses.


I would also use a string builder for the body, or better yet just type it all as one string, as it is not all that long (better to deal with those pesky _'s in VB than do a bunch of string appends or even use a string builder IMO).

For longer strings, or strings built more dynamically, Jason is spot on and you should look into using the StringBuilder class.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Scratch that, while I was typing I could only see the body portion that you have commented out (which was pretty short). Use the string builder :)

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top