Community discussion forum
Sending Email With an Attachment
-
This thread is for discussions of Sending Email With an Attachment.
-
Advertisement
Simply the fastest line-level profiler for .NET ever
“The low overhead means it has minimal impact on the execution of my program”
Mark Everest, Development Team Leader, Renault F1 Team Ltd.Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now
-
I am pretty new to VB.net programming and I seem to be missing a critical element to understanding how to use these code samples. For example the code below taken from this site does not work for me. VB underlines the two items surrounded by ** in the sample code below and says that "type Mail Attachement is not defined" also says that "name smtpMail is not declared"
What am I missing - each time I try to download sample code I run into the same types of issues????
Thanks!
Dim oMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
oMsg.From = "noone@nobody.com"
oMsg.To = "someone@somewhere.com"
oMsg.Subject = "Email with Attachment Demo"
oMsg.Body = "This is the main body of the email"
Dim oAttch As *MailAttachment = New MailAttachment("C:\myattachment.zip")
oMsg.Attachments.Add(oAttch)
SmtpMail.Send*(oMsg) -
Do I double click the forum to enter this code?
AND PLEASE KEEP THE TUTORIALS ON THIS COMING!!
javascript:smilie('
')
javascript:smilie('
') -
Hi,
I am using XML Text reader in PDA application to read large XML file, its working in Emulator but not in the PDA device. SO if any body can give suggetion, I will be thankful.
Ramakrishna Tulluri
India -
First Add Reference to System.Web.Dll
Go to top Menu
-Project
-Add References
Select System.Web.dll
Use this Coding
oMsg.From = Me@Here.com"
oMsg.To = "He@There.com"
oMsg.Subject = "Dit is my Afrikaanse Boodskap"
oMsg.Body = "Ek wil dit bysit"
Dim oAttch As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment("C:\ftpfile.txt")
oMsg.Attachments.Add(oAttch)
System.Web.Mail.SmtpMail.Send(oMsg)
MessageBox.Show("Mail Message Send") -
One thing about this code - I am trying to send with a specific SMTP server and Need to utilize the appropriate Authentication to use that SMTP server..
Any Ideas on how to do that ?
I know I can specify the SMTP server but how do I Specify the Authentication (username and password) obviously I might not want to send this in the clear..Can anyone help .. -
I can't get System.Web.Mail name space on my system. Is there any installation problem??
Ram Kinkar Pandey
PRamkinkar@pisoftek.com
Priya International Softek Limited
India -
ok ive tried this code but it is not working, i keep getting the error----
<An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll>
<Additional information: Could not access 'CDO.Message' object.>
Please Help!!!
Kinghenery87@aol.com -
I have tried to attach to oMsg.Body a richtexbox text.
I found that it doesn't work this way. I presume is because I have to send html formated text or plain text.
But still, I would like to send formated texts (from my app) in order to have well designed e-mails to my receivers.
How I amm supposed to accomplished that? -
The code is simple and works fine with me!!!
-
Dim objSender As SmtpMail
objSender.SmtpServer = "SMTPMAILSERVER"
Dim objMsg As New MailMessage
objMsg.From = "email@server.com"
objMsg.To = "email@server.com"
objMsg.Subject = "Test HTML"
objMsg.BodyFormat = MailFormat.Html
objMsg.Body = "<html><h1>hello</h1></html>"
''
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/smtsperver") = "SMTPMAILSERVER"
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "SMTPUSERNAME"
objMsg.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "SMTPPASSWORD"
''
objSender.Send(objMsg) -
I have seen this format before and I believe that format is for VB System not a Web App - I am not sure if I stated my question clearly enough.
I am using .NET
from the client side I want to be able to send an email and specify the email server username and password.
I will retry that code just to be sure - I posted the message a while back and cant remember much.. -
hi
you can keep that code any where its not a problem whether a webpage calls it or a windows app.
whats important is that it works on the .net framework.
do you mean by client side, that you use javascript, if yes, you can use AJAX to call a function from the server side, without any trip to the server.
Regards -
Great Thanks
-
all u hav to do is add reference "System.web.dll" in ur project...
that u can do by :----
1) rite - clickin on ur project in da solution explorer and click on 'add reference'...
2) got to da 'COM' tab and add the dll i mentioned before...
![Smiley Face [:)]](/emoticons/emotion-1a.gif)
njoi...!!!
![Smiley Face [:)]](/emoticons/emotion-1a.gif)
-
i have to develop an application that can send emails to our clients through a vb.net application...
but da problm is dat i cant use a SMTP server... oderwise ther wudnt b ne problm @ all..!!!
help...
![Sad [:(]](/emoticons/emotion-6.gif)
-
I want someone to help me with answers to sending sms to mobile phones from my website.
-
to krishna reddy..
hi krishna how r u...
i m making an application in vb.net to send email using smtp server... but it dosnt work... even it does not send mail to spam...
if it is possible, then plz send me the coding of ur application and the procedure... to me by my email id... this is my colg project and it didnt work, help me plz....
plzzzzzzzzzzzzzzzzzzzzzzzzzzzz
thank u....
-
this is the vb.net coding .......
note:- this is the coding which uses the gmail smtp server, u need to enter the valid email id and password of gmail, then only this will work...
if u have any pblm then ask me any time...
my id is:- k.ashish237@gmail.com
Imports System.Net.Mail
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress("sender email")
MyMailMessage.To.Add(TextBox1.Text)
MyMailMessage.Subject = "subject title"
MyMailMessage.Body = "enter the body text message that u want to send"
For counter = 0 To ListBox1.Items.Count - 1
Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment(ListBox1.Items(counter))
MyMailMessage.Attachments.Add(Attach)
Next
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("yourid@gmail.com", "id password")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
MessageBox.Show("Email Sent")
Catch ex As SmtpException
MessageBox.Show(ex.Message)
End Try
End Subsame coding with the tools of vb.net......
hope this will help u....
Imports System.Net.Mail
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress(TextBox3.Text)
MyMailMessage.To.Add(TextBox1.Text)
MyMailMessage.Subject = TextBox2.Text
MyMailMessage.Body = RichTextBox1.Text
For counter = 0 To ListBox1.Items.Count - 1
Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment(ListBox1.Items(counter))
MyMailMessage.Attachments.Add(Attach)
Next
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential(TextBox4.Text, TextBox5.Text)
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
MessageBox.Show("Email Sent")
Catch ex As SmtpException
MessageBox.Show(ex.Message)
End Try
End Sub
Post a reply
Related discussion
-
Reading an RSS file in ASP .NET
by TimL (31 replies)
-
handling special character in xslt's
by bussureddy82 (1 replies)
-
String was not recognized as a valid DateTime.
by buvanasubi (22 replies)
-
Developer Fusion v2 - Announcement
by James Crowley (15 replies)
-
Get the Message - MSMQ
by amer_jamaeen (27 replies)
Related articles
Quick links
Recent activity
- Cheryl Tan replied to File Upload.. how?
- Bhim Singh replied to Problem after strong naming...
- Jack Russel replied to how do you hide all in VB6
- Barry Fensom replied to Problem with Input File
- Barry Fensom replied to Problem with Input File
- Mario Leggio replied to How to create ActiveX DLL i...
Enter your message below
Sign in or Join us (it's free).