468,771 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Sending email with attachments

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?
Oct 3 '06 #1
8 1637
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?
Oct 3 '06 #2
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...SMTP_EMail.asp

Scott Moore

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?
Oct 3 '06 #3
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?

Oct 3 '06 #4
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("fr**@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 &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?
Oct 4 '06 #5
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("fr**@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?
>
>

Oct 4 '06 #6
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:
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("fr**@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?
Oct 4 '06 #7
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?
Oct 4 '06 #8
You should also highlight items and press F1 then read about them an
see how else they can be used.
samoore33 wrote:
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?
>
>
Oct 4 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Sven Templin | last post: by
5 posts views Thread by morphex | last post: by
6 posts views Thread by Anuradha | last post: by
7 posts views Thread by Ray Booysen | last post: by
3 posts views Thread by lizii | last post: by
2 posts views Thread by Aneesh Pulukkul[MCSD.Net] | last post: by
7 posts views Thread by bleachie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.