Using java to validate outlook email address - java

Background:
There are some invalid email adress in our system. I want to find all these invalid addresses. Some of these address are outlook address and some are instant message (IM) address.
Issue:
I have meet an issue when use SMTP to validate email address.
SMTP works when validate outlook address like ab1234#outlook.com.
However, SMTP failed to validate instant message (IM) address like bob.archer#corpration.com which does exist.
Is there a method using java to validate instant message (IM) address.
Hope for your reply,
Thanks.

Apache commons provides a solid validator that can help you:
https://github.com/apache/commons-validator/blob/trunk/src/main/java/org/apache/commons/validator/EmailValidator.java
You can take a look the link above and use the methods of EmailValidator class.

Besides checking the email format (one or more alphanumeric and/or special characters followed by # with several more alphanumeric characters separated by at least one "."), the only way to validate anything is to actually attempt to use it, be that for email or for IM.

Related

Replace + with its unicode equivalent in a url

I need to test a login process with the beta server and the security policy was updated so that all users have a unique email address.
So I thought for testing the app I would just use this type of email address
"myemailaddr+a#gmail.com"
where the +a allows for a unique address. Then on each subsequent test I would use "+B" etc to ensure I have a unique email address.
All good with the server but when I try and place the URL into my android webView it wont allow me to log in. Another genuine email address works just fine.
SO, how do I replace a "+" in a url string with its Unicode value of "%2B" and is it possible to do so in a URL.
Here is the URL template:
https://team.mycompany.com/teambeta/Login.aspx?username=myemailaddr+a#gmail.com&password=xxxxxxxx&mobile=1&offSetHours=11&appDevice=AndroidAndroid
Is what I am hoping to acheive possible or do I need to go and create multiple unique email addresses for testing?
Use URLEncoder.encode(). See the documentation at https://developer.android.com/reference/java/net/URLEncoder.html
After struggling with the URL ideas and other suggestions on the net I simply replaced all instances of "+" with "%2B" as follows.
webURL = webURLBefore.replace("+", "%2B");
Works well. And I did not have to encode it as when I did I was strunggling to encode just the "+" and the whole URL was encoded and would not work.
Hope this helps someone.

JavaMail - Mask "from" address

I have a piece of software I am developing that includes user accounts and login/passwords. For password storage/protection, I am using an asymmetric salt+hash system, and thus, if a user forgets their password, I would like the software to send a password reset link to the user's email address.
My question is this: is it possible to send this email from an address that does not actually exist (like do-not-reply#myproject.com)? Alternatively, is there a way to send it from a real email address but to mask the "from" address and make it appear to the recipient as do-not-reply#myproject.com even if it truly came from myemail#gmail.com?
Yes, you can send the e-mail to appear to come from any address. It is important to recognize that there are two 'from' addresses - the envelope sender is often not displayed to the recipient but indicates the server that is sending the message. The 'from' address is different and is specified in the message headers. As this is what what the recipient sees, it sounds like you simply need to customize your 'from' address header in the message.
Note: Some users will have e-mail servers that require proof that your server is authorized to send e-mail from the domain in the 'from' header. You can do this with an SPF record on the mydomain.com DNS zone file.

Is it possible to mask/spoof email address while sending mail in Java

In simple word, whenever I will send mail to anyone (within same mail server) it should appears some fake email address i.e. fakemail#gmail.com but, when they reply to this mail, it should come to my actual email address that is realname#gmail.com.
Note: My both email addresses will use same domain name, but only difference will be fake and real username for that email. I needed for the privacy issue. So, that nobody can reply to my mail directly until I send any mail to them.
Ask your mail server administrator to setup an email forwarding for you.
This is not a Java specific question. What you are asking for is called an
Email alias, and is a standard functionality on mail servers.
You can use a fake "from:" field and a valid "reply-to:" field, but the only people that will be fooled by this are people who would not know how to send spam anyway.
Even if you can (see below) mask the From field, you are giving away your email address in the Reply-To field, so you are still revealing your email address. (And if you weren't, it wouldn't be possible to reply.) So go with #Anony-Mousse and find a proper solution.
Now, please note that there are two "from" fields: one in the SMTP envelope and another in the message data.
It is quite uncommon for current mail servers to let you fake the SMTP from, though it may be possible if the server is using raw SMTP without authorization.
You are more likely to be allowed to send an email with a custom "From" in the message body (which is the one mail clients display, unless you look att all headers). However, the mail server may require that it matches the user you authenticated as.

Sending mail by setting recipient address in setHeader() method - java mail

Is there any way to add Recipient address using setHeader() like
message.setHeader("To:","mail#domain.com");
I tried the above one and it is not working. Please correct me if I am wrong.
I need an alternative for the following code:
InternetAddress mail_to = new InternetAddress("mail_id#domain.com","Name_of_recipient");
message.addRecipient(Message.RecipientType.TO, mail_to);
My requirement is to skip RFC822 email format check.
The header name is "To", without the colon.
But you're not going to get very far with an incorrectly formatted address. Even if JavaMail doesn't detect the error, the server most likely will.

sending email using "bcc" without "to" in java application

I have read all the reference in stackoverflow. However, nothing matches in our goal. How can i use bcc in sendmail method in java?
According to the RFC for SMTP, RFC 2821 (link), it is not possible to send an email message without a To: header. (You cannot send an RCPT command without it, see section 3.3.)
As Dietrich mentions, that's not possible with the RFC. If the primary goal is to send to the bcc target email addresses, you could provide a dummy to email address (such as your own email address or a reply-to email), which would fulfill that technicality while still allowing you to send the email to the desired bcc targets.
msg.addRecipient(Message.RecipientType.BCC, new InternetAddress("joe#example.com"));
By default, JavaMail collects all the recipients specified on the Message object, including Bcc recipients, and uses them in the RCPT command to the SMTP server. The Bcc recipients won't show up in the message headers, however (which is the whole point of Bcc).

Categories