Problem With Mailto Start Process

W

Wayne Wengert

I am using a Sub (see below) to call the default mail application and pass a
list of email addresses and a subject. Most of the time this works perfectly
but occasionally I get an error ("System NullReferenceException: Object
reference not set to an instance of an object"). From what I've been able to
determine, this occurs when there is a username (left of the @) with a
period such as (e-mail address removed)). Has anyone seen this type of problem
and have suggestions on how to resolve it?

================ Code =====================
Public Sub StartDefaultMail( _

ByVal [To] As String, _

Optional ByVal Subject As String = "" _

)

Try

Dim psi As New ProcessStartInfo

psi.UseShellExecute = True

psi.FileName = _

"mailto:" & System.Web.HttpUtility.UrlEncode([To]) & _

"?subject=" & Subject

Process.Start(psi)

Catch ex As Exception

MsgBox("Exception: " & ex.ToString, MsgBoxStyle.Information, "Error")

Throw _

New Exception( _

"Default mail client could not be started.", _

ex _

)

End Try

End Sub
 
H

Herfried K. Wagner [MVP]

* "Wayne Wengert said:
I am using a Sub (see below) to call the default mail application and pass a
list of email addresses and a subject. Most of the time this works perfectly
but occasionally I get an error ("System NullReferenceException: Object
reference not set to an instance of an object"). From what I've been able to
determine, this occurs when there is a username (left of the @) with a
period such as (e-mail address removed)). Has anyone seen this type of problem
and have suggestions on how to resolve it?

Is it possible to get the callstack for the exception?
 
W

Wayne Wengert

Herfried;

Is this what you need?

at Microsoft.Win32.NativeMethods.ShellExecuteEx(ShellExeuteInfo info)
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startinfo)
at System.Diagnostic.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OfficeApp.Module1.StartDefaultNail(String To, String Subject) in c:\2005
myProjects\TestApp2\Module1.vb:line 100

Wayne
 
H

Herfried K. Wagner [MVP]

* "Wayne Wengert said:
Is this what you need?

Yes, but I still don't have an idea.
at Microsoft.Win32.NativeMethods.ShellExecuteEx(ShellExeuteInfo info)
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startinfo)
at System.Diagnostic.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OfficeApp.Module1.StartDefaultNail(String To, String Subject) in c:\2005
myProjects\TestApp2\Module1.vb:line 100

2005 -- are you using VS 2005 (CTP?)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top