Results 1 to 14 of 14

Thread: [RESOLVED] Sending mails - acting like a server

  1. #1

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Resolved [RESOLVED] Sending mails - acting like a server

    Hi...

    I have a software under contruction for a small firm. And it requires email functionality. That is, whenever the users in the main database reaches the payment date, an email will be send to that user as a reminder.
    Or, in certain period, the admin needs to send a notification mail to all the users in the main database.

    So, how can I incorporate that facility in my main app ?

    My present idea is to create a separate app for send the mails. That is, when the admin compose the mail and selects a bunch of users (as recipients) from the database, all the message will be saved to another database (for mailing application) and will start the mailing app. This mailing app will check it's database for any pending emails to be sent, and if there exists any pending mails, it will start sending one by one. After sending each mail, it will remove that from the database.

    What's your idea ? Does it sounds ok to you ?

    I don't want the user of my main app to know that there exist another program, running in background, sending emails.

    Thanks in advance...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #2
    Fanatic Member Satal Keto's Avatar
    Join Date
    Dec 2005
    Location
    Me.Location
    Posts
    518

    Re: Sending mails - acting like a server

    If you have a look at my signature you'll find a class that I created for sending emails from VB.Net. Feel free to incorporate it into your application (assuming you leave the comments intact).

    Here's an example of how the code would look;
    Code:
            Dim em As New Email("SMTP Host", "SMTP User", "SMTP Password")
            Dim res As Satal.Email.Email.sendEmailResult
    
            em.SMTPPort = 587
            em.UseEncryption = True
            em.Tos.Add("target email address") 'You can add many of these if you want
            em.subject = "This is a test subject"
            em.message = "This is a test message" & Environment.NewLine & "Yay new line"
            If em.addAttachment("C:\Users\Satal\Desktop\test.txt") Then
                res = em.sendEmail()
    
                Select Case res
                    Case Email.sendEmailResult.attachmentNotAvailable
                        MsgBox("The attachment can't be found")
                    Case Email.sendEmailResult.noMessage
                        MsgBox("Whats the point of sending an email with no message?")
                    Case Email.sendEmailResult.noSMTPDetails
                        MsgBox("You need to supply the details for your SMTP server")
                    Case Email.sendEmailResult.noSubject
                        MsgBox("You need to specify a subject")
                    Case Email.sendEmailResult.noToEmails
                        MsgBox("You have to specify someone to send to")
                    Case Email.sendEmailResult.successful
                        MsgBox("You've got spam")
                    Case Email.sendEmailResult.unableToConnect
                        MsgBox("Unable to connect to SMTP server")
                    Case Email.sendEmailResult.unknownError
                        MsgBox("Ow no, what went wrong?")
                End Select
            End If
    The code uses SMTP so you will need to be able to access your SMTP server from what ever computer the application is running on.

    Hope this helps

    Satal

  3. #3

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Thanks satal ...

    Can you tell me how to add that into my project ? (I mean the code from the blog)
    And what about sending emails to many people, from database ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Fanatic Member Satal Keto's Avatar
    Join Date
    Dec 2005
    Location
    Me.Location
    Posts
    518

    Re: Sending mails - acting like a server

    No worries

    You would create a new class in your project called Email, then copy and paste the code from my website into that class (overwriting the pre-added code).
    You can add as many email addresses as you want to the To property, you also have the capability to use Carbon Copies (through the CC property) and Blind Carbon Copies (through the BCC property). So you would need to get a list from your database of all the emails you need to send then add them to one of those as appropriate.

  5. #5

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Quote Originally Posted by Satal Keto View Post
    No worries

    You would create a new class in your project called Email, then copy and paste the code from my website into that class (overwriting the pre-added code).
    You can add as many email addresses as you want to the To property, you also have the capability to use Carbon Copies (through the CC property) and Blind Carbon Copies (through the BCC property). So you would need to get a list from your database of all the emails you need to send then add them to one of those as appropriate.
    Thanks...

    When we add so many addresses to the To field, isn't it visible to the receiver ?
    I mean, if I'm sending emails from GMail, with comma separated recipient ids, it is possible to view those ids for all the recipients !

    Or, will your code do a queuing mechanism, so that mail is send one by one ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Quote Originally Posted by Satal Keto View Post
    No worries

    You would create a new class in your project called Email, then copy and paste the code from my website into that class (overwriting the pre-added code).
    You can add as many email addresses as you want to the To property, you also have the capability to use Carbon Copies (through the CC property) and Blind Carbon Copies (through the BCC property). So you would need to get a list from your database of all the emails you need to send then add them to one of those as appropriate.
    Sorry to ask again.. But the code in your website already contains a class named EMAIL. So, I have to just copy that class code into my form ?

    What about the "namespace" ? I'm newbie here...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7
    Fanatic Member Satal Keto's Avatar
    Join Date
    Dec 2005
    Location
    Me.Location
    Posts
    518

    Re: Sending mails - acting like a server

    Ok what you need to do is right click on your applications name in the solution explorer and choose "Add" then "Class". It will then prompt you for a name for your class, call it "Email.vb", you will then have a new class with the following pre-added
    Code:
    Public Class Email
    
    End Class
    Delete all of that and then on my website hover your mouse over the code, in the top right hand corner of the code box, you will see a box with "<>" in it, click on this. You will then have a new window opened from which you can copy the code without any of the formatting.
    Once you have copied the code then go back to Visual Studio and paste all the code into the blank Email class.

    You can keep the namespace but you can also delete it. If you keep it then when you try to make an object of it, you will have to do something like
    Code:
    Dim em as new Email.Email()
    If you remove the namespace lines (one at the beginning and one at the end) you will have to do something like
    Code:
    Dim em as new Email()
    .

    If you put all the emails in the to address then everyone will be able to see it. You have two options if you want people not to see everyone else who the email is going to;
    1) Send out the emails one at a time
    2) Send the email to yourself, but have everyone who should be receiving the email added as a BCC (Blind Carbon Copy).

  8. #8

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Thanks Satal Keto...

    If I want to send the email one at a time, then I have to repeat the code in post#2. Right ?

    So, is it possible to use the already declared objects again ? I mean, how efficiently can I use them ?

    Example(Pseudocode):
    Code:
    for each addresse from database
        entire code from your post#2
    loop
    Am I in the right path ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  9. #9
    Fanatic Member Satal Keto's Avatar
    Join Date
    Dec 2005
    Location
    Me.Location
    Posts
    518

    Re: Sending mails - acting like a server

    Well I would declare the variable outside of the for loop and then just initialise them to appropriate values within the for loop.
    If the email is the same in each of them then you can just clear the collection of To, CC and BCC and then add the new emails to them.

  10. #10

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Thanks Satal Keto....

    Does your code support HTML email ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  11. #11

  12. #12

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending mails - acting like a server

    Glad to know...

    Thanks for the help.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  13. #13

  14. #14

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Sending mails - acting like a server

    Quote Originally Posted by Satal Keto View Post
    Just to let you know the new version of the Email class now supports HTML emails
    Thanks Satal...

    Next time when you update the code, try including the feature to retrieve emails from inbox.

    Good luck..

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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