Home All Groups Group Topic Archive Search About

Sending email with attachments

Author
3 Oct 2006 8:05 PM
Mark
Using VB.net 2005, I am trying to send an email with attachments in Outlook. 
I have tried using this article from Microsoft,
(http://support.microsoft.com/?kbid=313803), but I can't even get the dim
statements to work.  It says it needs to be declared and I have used the
reference 0utlook 11.0. Also, I used Imports
Microsoft.Office.Interop.Outlook.  Any ideas?

Author
3 Oct 2006 8:23 PM
Izzy
Add a reference too System.Net.Mail and use this code:

Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
Optional ByVal Body As String = "")

        Dim SendMessage As New SmtpClient
        Dim Message As MailMessage = New
MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
        Dim App As Attachment

        If Path.Length > 0 And File.Exists(Path) Then
            App = New Attachment(Path)
            Message.Attachments.Add(App)
        End If

        SendMessage.Host = My.Settings.EmailServer
        SendMessage.Send(Message)

    End Sub



Mark wrote:
Show quoteHide quote
> Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> I have tried using this article from Microsoft,
> (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> statements to work.  It says it needs to be declared and I have used the
> reference 0utlook 11.0. Also, I used Imports
> Microsoft.Office.Interop.Outlook.  Any ideas?
Author
4 Oct 2006 12:09 AM
Mark
Thanks for your response, but I guess I failed to tell you how new I am at
this.  When somebody sends me a piece of code, I just copy and paste it. 
When I did this on yours after I added the reference as Imports
System.Net.Mail, I got numerous errors in the code. I am assuming that &quot
means ".  But still, the My.Settings does not work.  Anything you can help
with?

Show quoteHide quote
"Izzy" wrote:

> Add a reference too System.Net.Mail and use this code:
>
> Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> Optional ByVal Body As String = "")
>
>         Dim SendMessage As New SmtpClient
>         Dim Message As MailMessage = New
> MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
>         Dim App As Attachment
>
>         If Path.Length > 0 And File.Exists(Path) Then
>             App = New Attachment(Path)
>             Message.Attachments.Add(App)
>         End If
>
>         SendMessage.Host = My.Settings.EmailServer
>         SendMessage.Send(Message)
>
>     End Sub
>
>
>
> Mark wrote:
> > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > I have tried using this article from Microsoft,
> > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > statements to work.  It says it needs to be declared and I have used the
> > reference 0utlook 11.0. Also, I used Imports
> > Microsoft.Office.Interop.Outlook.  Any ideas?
>
>
Author
4 Oct 2006 1:26 AM
Izzy
Try this:

Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
Optional ByVal Body As String = "")

        Dim SendMessage As New SmtpClient
        Dim Message As MailMessage = New
MailMessage("f***@somewhere.com", Too, "Subject goes here", Body)
        Dim App As Attachment

        If Path.Length > 0 And File.Exists(Path) Then
            App = New Attachment(Path)
            Message.Attachments.Add(App)
        End If

        SendMessage.Host = "ServerName or IP Address" 'Name Of Your
SMTP Server Goes Here
        SendMessage.Send(Message)

    End Sub





Mark wrote:
Show quoteHide quote
> Thanks for your response, but I guess I failed to tell you how new I am at
> this.  When somebody sends me a piece of code, I just copy and paste it.
> When I did this on yours after I added the reference as Imports
> System.Net.Mail, I got numerous errors in the code. I am assuming that &quot
> means ".  But still, the My.Settings does not work.  Anything you can help
> with?
>
> "Izzy" wrote:
>
> > Add a reference too System.Net.Mail and use this code:
> >
> > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > Optional ByVal Body As String = "")
> >
> >         Dim SendMessage As New SmtpClient
> >         Dim Message As MailMessage = New
> > MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
> >         Dim App As Attachment
> >
> >         If Path.Length > 0 And File.Exists(Path) Then
> >             App = New Attachment(Path)
> >             Message.Attachments.Add(App)
> >         End If
> >
> >         SendMessage.Host = My.Settings.EmailServer
> >         SendMessage.Send(Message)
> >
> >     End Sub
> >
> >
> >
> > Mark wrote:
> > > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > > I have tried using this article from Microsoft,
> > > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > > statements to work.  It says it needs to be declared and I have used the
> > > reference 0utlook 11.0. Also, I used Imports
> > > Microsoft.Office.Interop.Outlook.  Any ideas?
> >
> >
Author
4 Oct 2006 2:38 AM
Mark
I think I am getting it, but now it give me an error message andd asks me for
smtp authentication, which I guess is username and password.  I don't see
where that goes.  any ideas?

Show quoteHide quote
"Izzy" wrote:

> Try this:
>
> Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> Optional ByVal Body As String = "")
>
>         Dim SendMessage As New SmtpClient
>         Dim Message As MailMessage = New
> MailMessage("f***@somewhere.com", Too, "Subject goes here", Body)
>         Dim App As Attachment
>
>         If Path.Length > 0 And File.Exists(Path) Then
>             App = New Attachment(Path)
>             Message.Attachments.Add(App)
>         End If
>
>         SendMessage.Host = "ServerName or IP Address" 'Name Of Your
> SMTP Server Goes Here
>         SendMessage.Send(Message)
>
>     End Sub
>
>
>
>
>
> Mark wrote:
> > Thanks for your response, but I guess I failed to tell you how new I am at
> > this.  When somebody sends me a piece of code, I just copy and paste it.
> > When I did this on yours after I added the reference as Imports
> > System.Net.Mail, I got numerous errors in the code. I am assuming that "
> > means ".  But still, the My.Settings does not work.  Anything you can help
> > with?
> >
> > "Izzy" wrote:
> >
> > > Add a reference too System.Net.Mail and use this code:
> > >
> > > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > > Optional ByVal Body As String = "")
> > >
> > >         Dim SendMessage As New SmtpClient
> > >         Dim Message As MailMessage = New
> > > MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
> > >         Dim App As Attachment
> > >
> > >         If Path.Length > 0 And File.Exists(Path) Then
> > >             App = New Attachment(Path)
> > >             Message.Attachments.Add(App)
> > >         End If
> > >
> > >         SendMessage.Host = My.Settings.EmailServer
> > >         SendMessage.Send(Message)
> > >
> > >     End Sub
> > >
> > >
> > >
> > > Mark wrote:
> > > > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > > > I have tried using this article from Microsoft,
> > > > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > > > statements to work.  It says it needs to be declared and I have used the
> > > > reference 0utlook 11.0. Also, I used Imports
> > > > Microsoft.Office.Interop.Outlook.  Any ideas?
> > >
> > >
>
>
Author
4 Oct 2006 12:57 PM
Izzy
I use it with Exchange 2003 and don't ever have to supply a username a
password. Just a valid "from" address.

Try inserting this line of code:
SendMessage.Credentials = New Net.NetworkCredential("UserName",
"Password")

Give it a valid username and password.

Izzy


Mark wrote:
Show quoteHide quote
> I think I am getting it, but now it give me an error message andd asks me for
> smtp authentication, which I guess is username and password.  I don't see
> where that goes.  any ideas?
>
> "Izzy" wrote:
>
> > Try this:
> >
> > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > Optional ByVal Body As String = "")
> >
> >         Dim SendMessage As New SmtpClient
> >         Dim Message As MailMessage = New
> > MailMessage("f***@somewhere.com", Too, "Subject goes here", Body)
> >         Dim App As Attachment
> >
> >         If Path.Length > 0 And File.Exists(Path) Then
> >             App = New Attachment(Path)
> >             Message.Attachments.Add(App)
> >         End If
> >
> >         SendMessage.Host = "ServerName or IP Address" 'Name Of Your
> > SMTP Server Goes Here
> >         SendMessage.Send(Message)
> >
> >     End Sub
> >
> >
> >
> >
> >
> > Mark wrote:
> > > Thanks for your response, but I guess I failed to tell you how new I am at
> > > this.  When somebody sends me a piece of code, I just copy and paste it.
> > > When I did this on yours after I added the reference as Imports
> > > System.Net.Mail, I got numerous errors in the code. I am assuming that "
> > > means ".  But still, the My.Settings does not work.  Anything you can help
> > > with?
> > >
> > > "Izzy" wrote:
> > >
> > > > Add a reference too System.Net.Mail and use this code:
> > > >
> > > > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > > > Optional ByVal Body As String = "")
> > > >
> > > >         Dim SendMessage As New SmtpClient
> > > >         Dim Message As MailMessage = New
> > > > MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
> > > >         Dim App As Attachment
> > > >
> > > >         If Path.Length > 0 And File.Exists(Path) Then
> > > >             App = New Attachment(Path)
> > > >             Message.Attachments.Add(App)
> > > >         End If
> > > >
> > > >         SendMessage.Host = My.Settings.EmailServer
> > > >         SendMessage.Send(Message)
> > > >
> > > >     End Sub
> > > >
> > > >
> > > >
> > > > Mark wrote:
> > > > > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > > > > I have tried using this article from Microsoft,
> > > > > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > > > > statements to work.  It says it needs to be declared and I have used the
> > > > > reference 0utlook 11.0. Also, I used Imports
> > > > > Microsoft.Office.Interop.Outlook.  Any ideas?
> > > >
> > > >
> >
> >
Author
4 Oct 2006 1:54 PM
samoore33
Mark,

As a prior newbie I also did the same thing. I would cut and paste code
into my projects and see if it would work. I know it is frustrating,
but one way to learn is to try to get the code to work after you paste
it into your project. I know it is frustrating as hell, but it does
help with learning code.

Scott Moore

Mark wrote:
Show quoteHide quote
> Thanks for your response, but I guess I failed to tell you how new I am at
> this.  When somebody sends me a piece of code, I just copy and paste it.
> When I did this on yours after I added the reference as Imports
> System.Net.Mail, I got numerous errors in the code. I am assuming that &quot
> means ".  But still, the My.Settings does not work.  Anything you can help
> with?
>
> "Izzy" wrote:
>
> > Add a reference too System.Net.Mail and use this code:
> >
> > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > Optional ByVal Body As String = "")
> >
> >         Dim SendMessage As New SmtpClient
> >         Dim Message As MailMessage = New
> > MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
> >         Dim App As Attachment
> >
> >         If Path.Length > 0 And File.Exists(Path) Then
> >             App = New Attachment(Path)
> >             Message.Attachments.Add(App)
> >         End If
> >
> >         SendMessage.Host = My.Settings.EmailServer
> >         SendMessage.Send(Message)
> >
> >     End Sub
> >
> >
> >
> > Mark wrote:
> > > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > > I have tried using this article from Microsoft,
> > > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > > statements to work.  It says it needs to be declared and I have used the
> > > reference 0utlook 11.0. Also, I used Imports
> > > Microsoft.Office.Interop.Outlook.  Any ideas?
> >
> >
Author
4 Oct 2006 2:19 PM
Izzy
You should also highlight items and press F1 then read about them an
see how else they can be used.


samoore33 wrote:
Show quoteHide quote
> Mark,
>
> As a prior newbie I also did the same thing. I would cut and paste code
> into my projects and see if it would work. I know it is frustrating,
> but one way to learn is to try to get the code to work after you paste
> it into your project. I know it is frustrating as hell, but it does
> help with learning code.
>
> Scott Moore
>
> Mark wrote:
> > Thanks for your response, but I guess I failed to tell you how new I am at
> > this.  When somebody sends me a piece of code, I just copy and paste it.
> > When I did this on yours after I added the reference as Imports
> > System.Net.Mail, I got numerous errors in the code. I am assuming that &quot
> > means ".  But still, the My.Settings does not work.  Anything you can help
> > with?
> >
> > "Izzy" wrote:
> >
> > > Add a reference too System.Net.Mail and use this code:
> > >
> > > Private Sub SendEmail(ByVal Path As String, ByVal Too As String,
> > > Optional ByVal Body As String = "")
> > >
> > >         Dim SendMessage As New SmtpClient
> > >         Dim Message As MailMessage = New
> > > MailMessage(My.Settings.EmailFrom, Too, "EDI Transfer Report", Body)
> > >         Dim App As Attachment
> > >
> > >         If Path.Length > 0 And File.Exists(Path) Then
> > >             App = New Attachment(Path)
> > >             Message.Attachments.Add(App)
> > >         End If
> > >
> > >         SendMessage.Host = My.Settings.EmailServer
> > >         SendMessage.Send(Message)
> > >
> > >     End Sub
> > >
> > >
> > >
> > > Mark wrote:
> > > > Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> > > > I have tried using this article from Microsoft,
> > > > (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> > > > statements to work.  It says it needs to be declared and I have used the
> > > > reference 0utlook 11.0. Also, I used Imports
> > > > Microsoft.Office.Interop.Outlook.  Any ideas?
> > >
> > >
Author
3 Oct 2006 8:27 PM
samoore33
Mark,

I found this link, but not sure it will help you. I have not used VB
2005 and can not find the link I used for mailing with VB 2003. I will
look for it to see if it might help you.
http://www.codeproject.com/useritems/VB2005_SMTP_EMail.asp

Scott Moore

Mark wrote:
Show quoteHide quote
> Using VB.net 2005, I am trying to send an email with attachments in Outlook.
> I have tried using this article from Microsoft,
> (http://support.microsoft.com/?kbid=313803), but I can't even get the dim
> statements to work.  It says it needs to be declared and I have used the
> reference 0utlook 11.0. Also, I used Imports
> Microsoft.Office.Interop.Outlook.  Any ideas?