Access denied opening outlook with LOTS of emails

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
Hi

my program crashes when I want to load (a lot!) of email adresses in the BCC.
can someone tell me if Im doing something wrong (or is this a bug)


here's my code;
first, i select all of the items in the listview:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] X, intLstCount [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2]intLstCount = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lstView.Items.Count - 1
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] X = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] intLstCount
lstView.Items(X).Selected = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][SIZE=2] X
[/SIZE]

put all the emailadresses in a string, like:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] lstView_SelectedIndexChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] lstView.SelectedIndexChanged
strEmailto = ""
[/SIZE][SIZE=2][COLOR=#008000]'loop through the selected items and put in string seperated with ;
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] lvitem [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ListViewItem [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] lstView.SelectedItems
strEmailto = strEmailto & lvitem.SubItems(1).Text & ";"
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lblStatus1.Text = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lstView.SelectedItems.Count.ToString() & " van " & lstView.Items.Count & " cursisten geselecteerd."
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

then I "klik n send"
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] strToAddress, strSubject [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2]strToAddress = strEmailto
strSubject = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtSubject.Text
[/SIZE][SIZE=2][COLOR=#008000][COLOR=black]System.Diagnostics.Process.Start("mailto: ?BCC=" & strToAddress & "&Subject=" & strSubject & " ")[/COLOR]
[/COLOR][/SIZE]

this is the message:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll
Additional information: Access is denied

the Green marked code is:
System.Diagnostics.Process.Start("mailto: ?BCC=" & strToAddress & "&Subject=" & strSubject & " ")

When I click a few (around 85) myself, All goes OK:confused:
(Outlook opens and puts all the emailadresses in the BCC and fills in the subject.)

someone?
 
You most likely run into problems with the length of the string passed to process.start.
I find little info about this, but in .Net 2.0 documentation for ProcessStartInfo.Arguments it says 2003 characters limit.

Why not use the very simple System.Web.Mail to create your own mailer?
 
Last edited:
John, thanks for answering
your suggestion;
you mean that I send the emails directly to an SMTP server?
by the way I m doing a windows appl.
thx in advance
 
Well, note that system.web.mail is for VS03 and .Net 1.x.
It can be used in VS05 and .Net 2.0 also, but is depreciated and replaced (and extended) with the System.Net.Mail namespace.
 
Back
Top