473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

.Net Mail only goes to one

Bob
This is the function I use in a mailsender class in vb2005 using the
system.net.mail namespace
Public Function SendSMTPNetMail(ByVal msgFrom As String, _

ByVal msgTo As String, _

ByVal msgSubject As String, _

ByVal msgBody As String, _

Optional ByRef ExStr As String = "", _

Optional ByVal msgCC As String = "", _

Optional ByVal Attachments As String = "", _

Optional ByVal SMTPServer As String = "localhost") As Boolean

'Attachments is a semiclon separated string of the fully qualified path of
the attachment(s) if there is at least one

Try

Dim EmailMessage As New MailMessage

Dim AddressFrom As New MailAddress(msgFrom) 'there can only be one from
address

EmailMessage.From = addressFrom

EmailMessage.IsBodyHtml = False

EmailMessage.Subject = msgSubject

EmailMessage.Body = msgBody

'There can be multiple to adresses, there must be at least one

Dim ToArray() As String

msgTo = Trim(msgTo)

ToArray = msgTo.Split(";")

For Each EmailTo As String In ToArray

Dim ToAddress As New MailAddress(EmailTo)

EmailMessage.To.Add(ToAddress)

Next

'There could be multiple CC or no CC at all

msgCC = Trim(msgCC)

If msgCC > "" Then

Dim ccArray() As String

ccArray = msgCC.Split(";")

For Each CCaddress As String In ccArray

Dim addressCC As New MailAddress(CCaddress)

EmailMessage.CC.Add(addressCC)

Next

End If

Dim emailClient As New SmtpClient(SMTPServer)

emailClient.UseDefaultCredentials = True

emailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
'There can be multiple attachments

Dim AttachArray() As String

If Attachments <> "" Then

Attachments = Trim(Attachments)

If Len(Attachments) > 0 Then

AttachArray = Attachments.Split(";")

' Iterate through the attachment array collection

For Each Attachment As String In AttachArray

Dim attachFile As New Attachment(Attachment)

'Add each item to the collection

EmailMessage.Attachments.Add(attachFile)

Next

End If

End If

EmailMessage.Priority = MailPriority.High

emailClient.Send(EmailMessage)

Return True

Catch ex As FormatException

Dim log As New EventLog(My.Application.Info.ProductName, My.Computer.Name,
"SendSMTPNetMail")

log.WriteEntry(ex.Message, EventLogEntryType.Error, 122)

SendSMTPMailFailsToFile(ex.Message, msgFrom, msgTo)

ExStr = ex.Message

Return False

Exit Function

Catch ex As SmtpException

Dim log As New EventLog(My.Application.Info.ProductName, My.Computer.Name,
"SendSMTPNetMail")

log.WriteEntry(ex.Message, EventLogEntryType.Error, 123)

ExStr = ex.Message

Return False

Exit Function

End Try

End Function

The messages get sent OK, however if I enter two destination addresses (for
instance mine in my domain and then the same address again for testing) I
should get two copies of the same message sent to my email account. I only
get one. The other problem is that when I enter my email address on my
domain and my email address for hotmail in the CC I don't get a CC either at
my own address or my hotmail address. What am I doing wrong?

Any help would be appreciated.

Bob




May 11 '06 #1
1 1136
This sounds like a mail server issue. What mail server are you using. If
it is Exchange, your first problem is that exchange filters the address list
for any message that arrives and only delivers one copy a message to each
address on the list. If the same address appears more than once, Exchange
detects this and removes duplicate addresses. The second problem sounds
like a relay restriction at your SMTP server.

Mike Ober.

"Bob" <bd*****@sgiims.com> wrote in message
news:ey****************@TK2MSFTNGP03.phx.gbl...
This is the function I use in a mailsender class in vb2005 using the
system.net.mail namespace
Public Function SendSMTPNetMail(ByVal msgFrom As String, _

ByVal msgTo As String, _

ByVal msgSubject As String, _

ByVal msgBody As String, _

Optional ByRef ExStr As String = "", _

Optional ByVal msgCC As String = "", _

Optional ByVal Attachments As String = "", _

Optional ByVal SMTPServer As String = "localhost") As Boolean

'Attachments is a semiclon separated string of the fully qualified path of
the attachment(s) if there is at least one

Try

Dim EmailMessage As New MailMessage

Dim AddressFrom As New MailAddress(msgFrom) 'there can only be one from
address

EmailMessage.From = addressFrom

EmailMessage.IsBodyHtml = False

EmailMessage.Subject = msgSubject

EmailMessage.Body = msgBody

'There can be multiple to adresses, there must be at least one

Dim ToArray() As String

msgTo = Trim(msgTo)

ToArray = msgTo.Split(";")

For Each EmailTo As String In ToArray

Dim ToAddress As New MailAddress(EmailTo)

EmailMessage.To.Add(ToAddress)

Next

'There could be multiple CC or no CC at all

msgCC = Trim(msgCC)

If msgCC > "" Then

Dim ccArray() As String

ccArray = msgCC.Split(";")

For Each CCaddress As String In ccArray

Dim addressCC As New MailAddress(CCaddress)

EmailMessage.CC.Add(addressCC)

Next

End If

Dim emailClient As New SmtpClient(SMTPServer)

emailClient.UseDefaultCredentials = True

emailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
'There can be multiple attachments

Dim AttachArray() As String

If Attachments <> "" Then

Attachments = Trim(Attachments)

If Len(Attachments) > 0 Then

AttachArray = Attachments.Split(";")

' Iterate through the attachment array collection

For Each Attachment As String In AttachArray

Dim attachFile As New Attachment(Attachment)

'Add each item to the collection

EmailMessage.Attachments.Add(attachFile)

Next

End If

End If

EmailMessage.Priority = MailPriority.High

emailClient.Send(EmailMessage)

Return True

Catch ex As FormatException

Dim log As New EventLog(My.Application.Info.ProductName, My.Computer.Name,
"SendSMTPNetMail")

log.WriteEntry(ex.Message, EventLogEntryType.Error, 122)

SendSMTPMailFailsToFile(ex.Message, msgFrom, msgTo)

ExStr = ex.Message

Return False

Exit Function

Catch ex As SmtpException

Dim log As New EventLog(My.Application.Info.ProductName, My.Computer.Name,
"SendSMTPNetMail")

log.WriteEntry(ex.Message, EventLogEntryType.Error, 123)

ExStr = ex.Message

Return False

Exit Function

End Try

End Function

The messages get sent OK, however if I enter two destination addresses (for instance mine in my domain and then the same address again for testing) I
should get two copies of the same message sent to my email account. I only
get one. The other problem is that when I enter my email address on my
domain and my email address for hotmail in the CC I don't get a CC either at my own address or my hotmail address. What am I doing wrong?

Any help would be appreciated.

Bob





May 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andre Phandana | last post by:
Hi, I tried to send email from my server using mail() but the email goes to @xyz.com junk mail folders. Why is that so? How can I fix it? Thank you, --Andre Phandana
1
by: Stephajn Craig | last post by:
It's been a while since I posted here, but here goes. Our server is a Windows 2000 Server with Service Pack 3, IIS 5 with Lockdown Wizard applied. My first problem is related to...
0
by: techie | last post by:
I'm trying to use system.web.mail to send an email, but the smtp server requires authentication. I came across some info about fields property Dim mail As New MailMessage() mail.To =...
3
by: techie | last post by:
I'm trying to use system.web.mail to send an email, but the smtp server requires authentication. I came across some info about fields property Dim mail As New MailMessage() mail.To =...
1
by: Joe via DotNetMonster.com | last post by:
Hi, I'm trying out a test mail script but it doesn't seem to work. The error I get is that mail is not declared on the mail.To line. Also, do I need to specify the SMTP Server? I have it...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
0
by: sonu | last post by:
I want to create a application when any user send a mail mail goes to mail server from where mail goes to destination. i want create a application from where i can handel all the mail request...
5
by: Robert Dufour | last post by:
With system.web.mail in VS2003, doing some tests, using localhost from IIS as server, I noticed that my code queues the messages OK, but when changing sender addresses I see that the mail message...
2
by: joseph2000 | last post by:
Hi, I have problem with e-mails which are being send via System.Web.Mail.SmtpMail class but before describing the problem itself first I'd like to show shortly what I'm doing on the server. ...
6
by: =?Utf-8?B?TMOhemFybw==?= | last post by:
Hi everyone I've a simple ASP.NET Page that send a email using smtclient. The server is a Exchange and use my credentials to autentificated. The problem is that the send mail appear in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.