[RESOLVED] Sending mails - acting like a server
Hi...:wave:
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...:wave:
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 :D
Re: Sending mails - acting like a server
Thanks satal ...:wave:
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 ?
Re: Sending mails - acting like a server
No worries :D
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.
Re: Sending mails - acting like a server
Quote:
Originally Posted by
Satal Keto
No worries :D
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...:wave:
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 ?:confused:
Re: Sending mails - acting like a server
Quote:
Originally Posted by
Satal Keto
No worries :D
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 ?:confused:
What about the "namespace" ? I'm newbie here...:bigyello:
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).
Re: Sending mails - acting like a server
Thanks Satal Keto...:wave:
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 ?
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.
Re: Sending mails - acting like a server
Thanks Satal Keto....:wave:
Does your code support HTML email ?
Re: Sending mails - acting like a server
Not currently, I do plan on making that addition in a later version of the class
Re: Sending mails - acting like a server
Glad to know...:wave:
Thanks for the help. :)
Re: [RESOLVED] Sending mails - acting like a server
Just to let you know the new version of the Email class now supports HTML emails :)
Re: [RESOLVED] Sending mails - acting like a server
Quote:
Originally Posted by
Satal Keto
Just to let you know the new version of the Email class now supports HTML emails :)
Thanks Satal...:wave:
Next time when you update the code, try including the feature to retrieve emails from inbox. :)
Good luck..:thumb: