Results 1 to 11 of 11

Thread: [2005] Send Textfile to E-mail

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    [2005] Send Textfile to E-mail

    Hi all

    I want to know how to send a textfile to my e-mail is this possible?




    Already Thx







    ~NitroAfg

  2. #2
    Lively Member cageybee's Avatar
    Join Date
    Nov 2005
    Location
    Stanardsville, VA
    Posts
    81

    Re: [2005] Send Textfile to E-mail

    Here's some code I used.....prolly can be modified to send your textfile via smtp. Your email server must be configed to accept smtp traffic (I've only used this to send email to the email server on my network...not an isp-based one).

    Public Function Sendemail(ByVal subject As String, ByVal senderid As String, ByVal mailto As String)


    Try
    Try
    Dim Message As New MailMessage
    Message.To = (mailto)
    Message.From = (senderid)
    Message.Subject = subject
    Message.Body = "text of message"
    Try

    SmtpMail.SmtpServer = "Servernamehere"
    SmtpMail.Send(Message)

    Catch ehttp As System.Web.HttpException
    'Console.WriteLine("0", ehttp.Message)
    'Console.WriteLine("Here is the full error message")
    'Console.Write("0", ehttp.ToString())
    End Try
    Catch e As IndexOutOfRangeException
    ' Display usage instructions if error in arguments.
    'Dim use As usage = New usage
    'use.DisplayUsage()
    End Try
    Catch e As System.Exception
    ' Display text of unknown error.
    'Console.WriteLine("Unknown Exception occurred 0", e.Message)
    'Console.WriteLine("Here is the Full Error Message")
    'Console.WriteLine("0", e.ToString())
    End Try





    End Function
    Last edited by cageybee; Jul 8th, 2008 at 04:17 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    Re: [2005] Send Textfile to E-mail

    Thx but can you make an example of that

    smtp.uwp.edu

  4. #4
    Lively Member cageybee's Avatar
    Join Date
    Nov 2005
    Location
    Stanardsville, VA
    Posts
    81

    Re: [2005] Send Textfile to E-mail

    it kind of is an example based on the variable names used ...sorry for the lack of indention though. substitute smt.uwp.edu for "Severnamehere". I took out some debugging code that I apparently left in....sorry.

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Send Textfile to E-mail

    OK... you should really try to figure things out yourself before just asking for someone to give you a fully working example, but here is something that should help you out. I havent tested it so it may need modifying slightly to get it to work.

    vb Code:
    1. Dim mysmtpclient As System.Net.Mail.SmtpClient
    2.         Dim mymail As System.Net.Mail.MailMessage
    3.  
    4.         mysmtpclient = New System.Net.Mail.SmtpClient
    5.         mymail = New System.Net.Mail.MailMessage
    6.  
    7.         mysmtpclient.Host = "smtp.uwp.edu"
    8.         mysmtpclient.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
    9.         mysmtpclient.Port = 25
    10.  
    11.         mymail.From = New System.Net.Mail.MailAddress("[email protected]")
    12.         mymail.To.Add(New System.Net.Mail.MailAddress("[email protected]"))
    13.         mymail.Attachments.Add(New System.Net.Mail.Attachment("c:\pathtotextfilehere.txt"))
    14.         mymail.Subject = "Subject Here"
    15.  
    16.  
    17.         mysmtpclient.Send(mymail)

    All you should need to do is modify the username and password that get used and modify the path to the text file that you want to attach. You also need to change the To and From address. It should be fairly obvious where to do this.

    Oh and you can import the System.Net.Mail namespace to save having to type it out each time like I did.

    Hope that helps.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] Send Textfile to E-mail

    Quote Originally Posted by Nitroafg
    Hi all
    I want to know how to send a textfile to my e-mail is this possible?
    Already Thx
    ~NitroAfg
    Hi,

    If you mean that you want to sent an attachment (textfile) with your E mail application then see post #10 in this thread.

    http://www.vbforums.com/showthread.p...04#post3274804

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    Re: [2005] Send Textfile to E-mail

    [QUOTE
    mysmtpclient.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")

    [/QUOTE]

    What do you mean with Username Password my e-mails username and pass or something else ?

    BTW I want to send the e-mail to live (hotmail)

  8. #8
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Send Textfile to E-mail

    The username and password that is required to send emails through the smtp server you mentioned (smtp.uwp.edu). Its possible that this email server doesnt require a username and password but its unlikely. Where did you get this smtp server address from? I mean I assume its the server that you normally send emails through so you should have a username and password set in Outlook (or whatever email program you are using to send emails through that smtp server).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    37

    Re: [2005] Send Textfile to E-mail

    Quote Originally Posted by chris128
    The username and password that is required to send emails through the smtp server you mentioned (smtp.uwp.edu). Its possible that this email server doesnt require a username and password but its unlikely. Where did you get this smtp server address from? I mean I assume its the server that you normally send emails through so you should have a username and password set in Outlook (or whatever email program you are using to send emails through that smtp server).
    Sorry I thought that smtp.uwp.edu was the hotmail (live) smtp but I found the real one its smpt.live.com

    do you know the pass and username :P

    thx

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Send Textfile to E-mail

    I think your going about this all wrong. You dont have to use the hotmail server to send an email to a hotmail account... you can use any SMTP server that you have access to for this, typically it would be your company's email server or your ISP (internet service provider) email server.
    I assume its possible to connect to the smtp.live.com server and use it to send email using your normal hotmail username and password but I've never tried so cant confirm that.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Send Textfile to E-mail

    All kinds of good information: http://www.systemnetmail.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width