NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment
NetworkCredential and Attachment NetworkCredential and Attachment
NetworkCredential and Attachment
Go Back  Xtreme Visual Basic Talk > > > NetworkCredential and Attachment


Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2008, 10:29 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default NetworkCredential and Attachment


1. I am using following code to authenticate username and password from an e-mail address:
----
Dim mailClient As New System.Net.Mail.SmtpClient("mail.hot.ee", 25)

mailClient.Credentials = New System.Net.NetworkCredential(Kasutaja.Text, Parool.Text)
----
How can i make it as a MUST, to input username and password before it could send an e-mail ? - At the moment i can leave my username and password boxes empty and send e-mails.


2. Following code:
----
Dim attachment As System.Net.Mail.Attachment

If My.Computer.FileSystem.FileExists(TextBox1.Text) Then message.Attachments.Add(attachment)
----
It doesn't work, because it says "attachment" is a nullvalue

PS, i am trying to make an e-mail sender application.

Help would be greatful, thank you !

Last edited by Murt2003; 12-12-2008 at 03:03 PM.
Reply With Quote
  #2  
Old 12-16-2008, 03:13 AM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

1. Username and password for their actual email service? Or your own username and password specified by your ASP program?

2. If it's says it is null, check the values in debug and ensure that the attachment really is null. Also in debug mode you should be able to see why the attachment is not getting a value put in. By the 2 lines of code you specified, you do indeed have a null value. You never initialized the attachment. I'll assume there is more code to that, though.
Reply With Quote
  #3  
Old 12-16-2008, 11:25 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

1. Username and password from your e-mail account.

2. As a matter of fact i was trying to get through with those two lines of code
I thought it would work like this.
So which part am I missing here ? - Could you help me with my code ?


Thanx !
Reply With Quote
  #4  
Old 12-16-2008, 10:16 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

1. How is it possible that you can get into someone's email without using their username and password? You said you can send emails without anything in the textboxes...? That's definitely not the case and if it is, they really should be alerted their email has no security. I think what you mean is you can bypass the check of seeing if they put information in, correct? If not, explain in even further detail, please.

2. Well, you say, Dim the variable as an attachment, and then add it to the collection. There's nothing in the attachment to put in the collection. You need to say attachment = something, then you can add it to the collection.
Reply With Quote
  #5  
Old 12-17-2008, 12:50 PM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

1. I can send e-mails wihtout any usernames neither passwords and yes, maybe they have bad security. I put here all the code. Maybe you still can help with this.
----CODE----
Imports System.Net
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim message As System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient("mail.hot.ee")
Dim attachment As System.Net.Mail.Attachment

message = New System.Net.Mail.MailMessage("MyEmail@hotmail.com", "SendingTo@Email.com", "Subject", "Msg")
If My.Computer.FileSystem.FileExists(TextBox1.Text) Then message.Attachments.Add(attachment)

Dim basicAuthenticationInfo As New System.Net.NetworkCredential(textbox2.text, textbox3.text)
smtp.UseDefaultCredentials = False
smtp.Credentials = basicAuthenticationInfo

Try
smtp.Send(message)
MessageBox.Show("Well, the mail message appears to have been a success!", " Successful?", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch exc As Net.Mail.SmtpException
MessageBox.Show(exc.StatusCode.ToString, " Something Happened?", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End Sub
End Class
----CODE----

2. Thanx, i got it working !

Last edited by Murt2003; 12-17-2008 at 02:09 PM.
Reply With Quote
  #6  
Old 12-17-2008, 09:41 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

I could be wrong but it looks more to me like you're spoofing the email address, not really sending it from hotmail. You're simply telling the program, "This is my email address that people should see." However, that's not really the case. If they were to examine where the message came from, they'd realize it's from the mail.hot.ee SMTP, not hotmail, that is why you do not need a username/password. It's never logging into hotmail. Essentially, you could write in bill.gates@microsoft.com in there, and people would see that as your email.
Reply With Quote
  #7  
Old 12-19-2008, 01:06 PM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

Even if i do use my hot.ee account it never asks for authentication...

Dim smtp As New System.Net.Mail.SmtpClient("mail.hot.ee")

message = New System.Net.Mail.MailMessage("myAcc@hot.ee", "HisAcc@hot.ee", "Subject", "Msg")

I haven't seen any other posts or forums about such a problem also.

Don't you have an example for asking authentication ?
Could you try or something ?

Thank you very much !
Reply With Quote
  #8  
Old 12-19-2008, 08:51 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Yes, but it's STILL spoofing the email. You're simply using the SMTP to transfer out the message with that email address as the email people see. So you could again, put murt2003@hot.ee and it would send. There could be an email address called murt2003 and there could not be, doesn't matter. It's simply telling the person who opens your message to see that email address, even though it's not "really" that per se.

To get around this, you need to implement your own front-end security check, such as hotmail does. It asks for a username/password before they can log in, and then send out email.

Basically, you need to have access to their credentials via database or something like Windows Active Directory. If you have no such access, it is useless to continue on. If you have such access, let me know, and we can go from there.
Reply With Quote
  #9  
Old 12-20-2008, 02:15 PM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

I can send e-mails only from addresses that really exist.

I am afraid that I am too newby for such a task. Honestly i have no idea how to see if i have permission for their credentials.
----------------------------------------------------------------------------------------
For example look at this link: http://www.vbforfree.com/?p=282
It says there...

And now you can set up your Credentials for your Login info. (Username and Password)
'Setup your account information for authorization...
smtp.Credentials = New System.Net.NetworkCredential("yourUsername@yourmail.com", "password")

...and it seems to work with others !
----------------------------------------------------------------------------------------
Is there a possibility, that i could get your MSN for faster chatting ?
Btw, you have been very helpful !

Thank you !

Last edited by Murt2003; 12-20-2008 at 02:40 PM.
Reply With Quote
  #10  
Old 12-20-2008, 07:51 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Ok I get it...I've never had to use credentials before but it looks pretty simple. All the code you need is in that article. What you're probably asking is how to put the password in.

Set up a textbox and pass in the text to the password field. Let's say you call it TextBox1. On the postback, it would be this:

smtp.Credentials = New System.Net.NetworkCredential("yourUsername@hot.ee", TextBox1.Text)

I'll assume the send will fail if the password is incorrect. You will have to alert the user about that. I don't have MSN for you to contact me, sorry. I'll try to respond quicker though. Let me know exactly what you need from this. Your questions are extremely vague...and in fact, the only real question you asked in that last post was if I had MSN.
Reply With Quote
  #11  
Old 12-21-2008, 02:00 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

Now we got to the point ...
The thing is, that i do use textboxes for username and password, but i can simply leave them empty and no error occures. That means: My networkcredentials are not doing anything at all. Now i want to know why !

And don't bother responding quicker than before because you are doing very well xD ! I just thought if you had a MSN then we could talk fluently about my issue.

Thank you very much !
Reply With Quote
  #12  
Old 12-21-2008, 02:20 AM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Try something along these lines and let me know if it has any success:
Code:
imports System.Net.Mail;
Code:
Dim message As New MailMessage("senderID@domainName.com",_
    "receiverID@domainName.com","subject of the Message ",_
    "body fo the message ")
' create and add the attachment(s)
Attachment attachment = new Attachment("sample.doc",
                        MediaTypeNames.Application.Octet)
  message.Attachments.Add(attachment)

' create SMTP Client and add credentials
Dim emailClient As New new SmtpClient("Your SMTP Server")

' Email with Authentication
Dim SMTPUserInfo As New new NetworkCredential("userID", "password", "domainName")
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo

' Send the message
emailClient.Send(message)
The Web.config file:
Code:
 <?xml version="1.0"?>
  <CONFIGURATION> 
   <SYSTEM.NET> 
        <MAILSETTINGS>
          <SMTP from="authicationEmailID@yourdomain.com"> 
           <NETWORK password="password" 
                 userName="UserID" port="25" 
                 host="smtp.yourdomain.com"/>   
          </SMTP> 
        </MAILSETTINGS> 
     </SYSTEM.NET> 
  </CONFIGURATION>
Reply With Quote
  #13  
Old 12-21-2008, 10:05 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

Where do i enter the web.config file ?

I didn't touch the web.config and credentials still don't work.

Last edited by Murt2003; 12-21-2008 at 10:24 AM.
Reply With Quote
  #14  
Old 12-21-2008, 01:24 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

The web.config file should be with all your other files in the application.
Reply With Quote
  #15  
Old 12-21-2008, 02:46 PM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

If i tried to add it, i got a bunch of errors :P. I have never used that conf before. Exactly where do i add it ? Do i have to delete everything else and replace with that one ?

Thank you !
Reply With Quote
  #16  
Old 12-21-2008, 03:06 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

No just put the information anywhere between the tags. There will probably be other stuff between the tags. I don't know because I don't know what your config file looks like. Let's try another route though, something easier:
Code:
Dim message As System.Net.Mail.MailMessage = new System.Net.Mail.MailMessage("FromAddress", "ToAddress", "Subject", "Message")
Dim mailClient As System.Net.Mail.SmtpClient = new System.Net.Mail.SmtpClient("smtpAuthServerAddress")

' Set credentials for the smtp server
mailClient.Credentials = new System.Net.NetworkCredential("Username", "Password")

Try
   mailClient.Send(message)
Catch
   ' Do whatever here
End Try
Reply With Quote
  #17  
Old 12-21-2008, 03:47 PM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

Without web.config it didnt work.

I tried to put it between lines but occured an error:

Unexpected XML declaration...
Reply With Quote
  #18  
Old 12-21-2008, 09:46 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Ok...well, I've given you all the code and information I can. Maybe someone else can solve this for you.

If you have access to the username/password database we can try an alternative approach.
Reply With Quote
  #19  
Old 12-22-2008, 03:53 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

OK, i deeply thank you for such a messy problem !

Thank you very much !
Reply With Quote
  #20  
Old 12-22-2008, 11:39 AM
Murt2003 Murt2003 is offline
Newcomer
 
Join Date: Dec 2008
Posts: 16
Default

Maybe this could be done with something like this ?

Dim myCred As New NetworkCredential(SecurelyStoredUserName,SecurelyStoredPassword,Secure lyStoredDomain )

Dim myCache As New CredentialCache()

myCache.Add(New Uri("www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("app.contoso.com"), "Basic", myCred)

Dim wr As WebRequest = WebRequest.Create("www.contoso.com")
wr.Credentials = myCache


This is an example i got from somewhere.
What do you say ?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment NetworkCredential and Attachment
NetworkCredential and Attachment
NetworkCredential and Attachment
 
NetworkCredential and Attachment
NetworkCredential and Attachment
 
-->