I have an email programme that works sometimes, but mostly comes up with a general Mapi failure. I am at a loss as to the reason, but it may be a good idea to not use the mapi controls anymore if it is going to cause errors. I have looked at SMTP options using system.net.mail but I cant figure out how to send attachments, also it is nice to have a copy of the email in the default mail client which MAPI does. Anyone got any ideas as the best way to send emails using vb.net.

You can add an attachment to an email by doing the following:

Dim oMail As New Net.Mail.MailMessage
oMail.Attachments.Add(New Net.Mail.Attachment("Path to my file"))

As for saving a copy local, you could parse the email into a text file and save it.

Yes this worked very well for using SMTP direct, I think I will change to using that method, I wonder if there is a method which can add to the default mail client sent items, even though it won't actually be sending the email.

What mail client are you using?

Outlook?
Mozilla?
Live?

Windows live mail.

Althought this code works most of the time, when I get an error it doesn;t help much, is there a way offinding out details of errors.
I have tried.

Dim smtperror As New SmtpException
            x = smtperror.Message

and I get x equalling 100 ??

Try something like this:

Try

'Your code here

Catch ex As Exception
    MsgBox(ex.ToString)
End Try

This will show the error message, the inner exception, and the stack trace all in one dialog box.

Post the image of the resulting error here.

Thanks thats great.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.