Create Email, attach file and send using default mail client ...

  • Thread starter Thread starter Landley
  • Start date Start date
L

Landley

Hello,

Is there a way of creating an email, attaching a file and sending using the
client's default mail client?

I am looking for a none email client specific solution that does not involve
specifying parameters such as mail servers etc.

Cheers,

Landers
 
Hi Landley,

Almost, but you have to have an smtp server reference, or else the system
does not know what it is. You could find some esoteric way to query the
current accounts inside Outlook or Outlook Express, but even the query
wouldn't know if that were a valid smtp server.

Here's the easiest way to do it:
Begin your class with a reference to system.web.mail:
Imports System.Web.Mail

Then add the code as appropriate:
Dim msg As New MailMessage

msg.To = "(e-mail address removed)"

msg.From = "(e-mail address removed)"

msg.Subject = "test subject"

Dim astring1 As String = "c:\my documents\wzo letter.doc"

msg.Attachments.Add(New MailAttachment(astring1))

Dim astring2 As String = "c:\my documents\visual basic notes.doc"

msg.Attachments.Add(New MailAttachment(astring2))

Dim astring3 As String = "\\imcsql\data\imcapps\sqldiag.txt"

msg.Attachments.Add(New MailAttachment(astring3))

msg.Cc = "(e-mail address removed)"

SmtpMail.SmtpServer = "mail.xxxxx.com"

Try

SmtpMail.Send(msg)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

HTH,

Bernie Yaeger
 
Landley,

Not using the default mail client in the way you said, when you are sure
that is Office Outlook than you can using the interop too that.

For sending mail with attachment, you can use Bernie's sugestion, however
be aware that for that you should have at least NT5x clients and the mail is
not saved in the users mailclient.

When you search this newsgroup you will find tons of questions about this.

Cor

"Landley"
 

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

Back
Top