|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
.Net Mail only goes to onesystem.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 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. Show quoteHide quote "Bob" <bduf***@sgiims.com> wrote in message news:ey%23LOcRdGHA.4108@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 > > > > > > > > > > >
strange behavior , has someone an explanation for this ??
how to not use VB.net Format Strings in DataGrid Column Style actual record Windows Forms and Console Application [VB2005EE] accessing control-specific functions via form's ActiveControl Data type conversion question Developing ASP.NET 2.0 Applications textbox numeric with 2 decimals editing XML relationship lines |
|||||||||||||||||||||||