[RESOLVED] unable to send multiple emails through SMTP
Hi
Im trying to send multiple emails through a smtp server.
Sending a single one goes OK (even with att).
but when trying to send more than one....
the error raised is:
Console.WriteLine(exp.Message) gives:
Could not access 'CDO.Message' object.
Console.WriteLine(exp.InnerException.Message.ToString) gives:
Exception has been thrown by the target of an invocation.
Im using the code from MS 101 examples:
I build a string (strEmailTo) with the emailadresses. and seperate the emailadresses by ';' (to be sure, I remove the last ; one)
I've been trying diffent way and googled myself dizzy.
Maybe anyone here seen this before and know a solution
VS 2003: 7.1.3088
.net framework: 1.1.4322
Hi
Im trying to send multiple emails through a smtp server.
Sending a single one goes OK (even with att).
but when trying to send more than one....
the error raised is:
Console.WriteLine(exp.Message) gives:
Could not access 'CDO.Message' object.
Console.WriteLine(exp.InnerException.Message.ToString) gives:
Exception has been thrown by the target of an invocation.
Im using the code from MS 101 examples:
I build a string (strEmailTo) with the emailadresses. and seperate the emailadresses by ';' (to be sure, I remove the last ; one)
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] sb [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] StringBuilder
[/SIZE][SIZE=2][COLOR=#008000]' Build the email message body.
[/COLOR][/SIZE][SIZE=2]sb.Append("The following email was sent to you from the Send Mail How-To " & _
"sample application:")
sb.Append(vbCrLf)
sb.Append(vbCrLf)
sb.Append("SUBJECT: ")
sb.Append(Trim([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtSubject.Text))
sb.Append(vbCrLf)
sb.Append(vbCrLf)
sb.Append("MESSAGE: ")
sb.Append(Trim([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtMessage.Text))
sb.Append(vbCrLf)
[/SIZE][SIZE=2][COLOR=#008000]' Creating a mail message is as simple as instantiating a class and
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' setting a few properties.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mailMsg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] MailMessage
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] mailMsg
.From = strSender
.To = strEmailto.Trim
[/SIZE][SIZE=2][COLOR=#008000]'.Cc = txtCC.Text.Trim
[/COLOR][/SIZE][SIZE=2].Bcc = Mid(strEmailto, 1, Len(strEmailto.Trim) - 1)
.Subject = txtSubject.Text.Trim
.Body = sb.ToString
[/SIZE][SIZE=2][COLOR=#008000]'.Priority = CType(cboPriority.SelectedIndex, MailPriority)
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] IsNothing(arlAttachments) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mailAttachment [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] mailAttachment [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] arlAttachments
.Attachments.Add(mailAttachment)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Set the SmtpServer name. This can be any of the following depending on
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' your local security settings:
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' a) Local IP Address (assuming your local machine's SMTP server has the
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' right to send messages through a local firewall (if present).
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' b) 127.0.0.1 the loopback of the local machine.
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' c) "smarthost" or the name or the IP address of the exchange server you
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' utilize for messaging. This is usually what is needed if you are behind
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' a corporate firewall.
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' See the Readme file for more information.
[/COLOR][/SIZE][SIZE=2]SmtpMail.SmtpServer = strSMTP
[/SIZE][SIZE=2][COLOR=#008000]' Use structured error handling to attempt to send the email message and
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' provide feedback to the user about the success or failure of their
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' attempt.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]SmtpMail.Send(mailMsg)
lstAttachments.Items.Clear()
lstAttachments.Items.Add("(No Attachments)")
MessageBox.Show("Your email has been successfully sent!", _
"Email Send Status", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] exp [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MessageBox.Show("The following problem occurred when attempting to " & _
"send your email: " & exp.Message, _
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Console.WriteLine(exp.Message)
Console.WriteLine(exp.InnerException.Message.ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE]
I've been trying diffent way and googled myself dizzy.
Maybe anyone here seen this before and know a solution
VS 2003: 7.1.3088
.net framework: 1.1.4322
Last edited: