|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sending email with attachmentsUsing 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? 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? 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? 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? > > 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 " > 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? > > > > 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? > > > > > > > > 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? > > > > > > > > > > > > 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 " > 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? > > > > 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 " > > 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? > > > > > > 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?
Data Set to Excel ?
vb.net serial IO problem writing commands to command prompt in VB.NET Open folders to process files automatically [Newbie] Customize Anchor properties ? SelectedIndexChanged causes selectedindex to reset to -1? How hard would this be? Q: Activated Regular Expression Playing Wav-files over 2 soundcards in VB.NET |
|||||||||||||||||||||||