Comments (7)
Any suggestions? Adding a flag 'test mode' is easy enough so that it won't
actually send emails.
How would you like to perform the validations?
Original comment by b.bottema
on 1 Aug 2012 at 10:38
from simple-java-mail.
Consider this:
// SmtpReceiver is a simple interface definition from simple-java-mail.
// The interface looks similar to interface used to talk to the remove server, but perhaps at a higher level of abstraction.
// In another words, I would like to see SmtpReceiver get the "to", "from", "headers", etc., but not actually see the "helo" handshaking, etc.
// I'd also like to make sure that simple-java-mail still performs all of the other stuff it does like validation.
// The SmtpReceiver is the last part of the chain.
// Oh, I'd also like to be able to have SmtpReceiver throw IOExceptions to similate network/server failures, etc.
SmtpReceiver aSmtpFakeReceiver = <my mock or fake smtpreceiver>
Mailer mailer = new Mailer(... aSmtpFakeReceiver ...);
Thoughts?
Original comment by [email protected]
on 1 Aug 2012 at 12:06
from simple-java-mail.
I've given this some thought. I think it would be a good addition as it allows me to test my own code better as well. I would probably not go with an interface, but a concrete class which allows you to override the default behavior.
Thoughts?
from simple-java-mail.
Hi @bbottema ,
in my unit tests I have succesfully used Wiser (https://github.com/voodoodyne/subethasmtp/blob/master/Wiser.md) and Wiser Assertions (https://github.com/kemitix/wiser-assertions) to test send. Maybe it could be of any help to you.
For example:
@Before
public void setup() {
wiser = new Wiser();
wiser.setPort(2500);
wiser.start();
}
@Test
public void shouldSendEmail() {
...
WiserAssertions.assertReceivedMessage(wiser)
.from("[email protected]")
.to("[email protected]")
.withSubject("test mail")
.withContentContains("duke nukem");
}
this is my first piece of "markdown" so be indulgent .
from simple-java-mail.
Your markdown is fine :) I edited so that it has java syntax highlighting now and you can see how easy that is.
Regarding your comment on Wiser, that's nice actually. I didn't know of it before. I will let this sink in for some time, because I can't tell if this solution is enough and if the dependency is one I'm comfortable enough with for testing emails going through Simple Java Mail.
from simple-java-mail.
I've given this a lot of thought and I'm going to decline this feature, as mocking this library is not the right layer to mock.
Simple Java Mail is a simple pass-through solution translating high abstractions (Email instances) to low level Java Mail SMTP objects (MimeMessages etc.). You should test if your Email objects are being populated properly rather than if the messages being sent on low-level are populated properly. In the latter case you would simply be testing either Simple Java Mail itself or Oracle's SMTP implementation.
Simply mock a Mailer
instance directly using something like EasyMock or some other library and test if mailer.sendMail(Email)
is being invoked with the expected Email
object.
For internal testing of Simple Java Mail, however, I might use WiserAssertions as suggested, but that is to test if Simple Java Mail works as expected and so it is unrelated to this issue here.
from simple-java-mail.
Simple Java Mail now uses Wiser internally to test mail sending correctness!
from simple-java-mail.
Related Issues (20)
- java.lang.ClassCastException: org.simplejavamail.email.internal.EmailStartingBuilderImpl cannot be cast to org.simplejavamail.api.email.EmailPopulatingBuilder HOT 1
- Regression bug #461: Simple Java Mail always requires DKIM/SMIME modules HOT 1
- Maintenance: Let Mailer implement AutoCloseable, so it shuts down the connection pool automatically when disposed of by Spring HOT 3
- Security: Medium severity vulnerability is detected in org.bouncycastle transitive dependency HOT 3
- Dependency problems around jakarta.mail HOT 5
- S/MIME implementation is broken HOT 1
- Erros send mail with Subject in multiple lines HOT 3
- Convert EML to MSG format HOT 1
- Support sending e-mails directly to recipient SMTP server (MX) HOT 5
- Bugfix: Add missing support for multiple reply-to addresses HOT 3
- [Bug] .msg inside .msg becomes .eml HOT 5
- Enhancement: Add configuration metadata for Spring Boot application properties HOT 6
- MailerImpl#close Javadoc clarification HOT 4
- Enhancement: Support Exchange proprietary addresses (X.500 DAP) HOT 4
- SmimeUtil configurable signature algorithm HOT 2
- All the Emails are sending after restarting the tomcat container. HOT 1
- Bug: Multiple attachments with same name get the same Content-ID, causing them to refer to the same file content HOT 4
- Enhancement: don't crash on invalid empty embedded images when parsing Outlook messages HOT 1
- Bug: 'IllegalArgumentException: emailAddressList is required' when parsing mail with incorrect recipients from Outlook message HOT 1
- Enhancement: add native support for overriding envelope-level receiver(s) HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-java-mail.