473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1815
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
5
by: morphex | last post by:
Hi, I have an email that's in the utf-8 encoding, and I'm getting this error message when I try to send it using smtplib: * Module smtplib, line 688, in sendmail * Module smtplib, line 485,...
4
by: Liz Patton | last post by:
Here's the exception: System.Exception: Unable to send mail: Could not access 'CDO.Message' object. ---> System.Web.HttpException: Could not access 'CDO.Message' object. --->...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
7
by: Ray Booysen | last post by:
Hi all I'm sending email via ASP.NET in HTML mode. Each email has exactly one attachment and I do have full access to the SMTP server. However, if I send the email in HTML format, the...
3
by: lizii | last post by:
Hey there - hopefully last newbie question i will ask for a while! I want my application to work where you click a button - and it either: a) open a email application - insert the correct email...
2
by: Aneesh Pulukkul[MCSD.Net] | last post by:
Hi, I have a HTML page and associated images. I need to send the HTML as email -the email should also display the images at respective places. So am sending the content of HTML file as...
7
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any...
7
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.