• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending mails from someone's address

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When sending emails through the JavaMail API, can we change the "From:" field, to another email address (even though we don't know the password of it)?

I found that some online services do so.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is - javax.mail.internet.MimeMessage has a method called setFrom to do this.

This feature may be used for spamming / phishing alright, or any other reason for identifying yourself as someone else. However, you can do that from (nearly) any email client. It may require to change the account settings, but that's easily done.

Any replies sent to those emails won't be readable by you though, since that does require the password.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, it doesn't work as I expected. It changes the "Display Name" of the from address (like From: "Treimin Clark"), but it also shows the original address. That means the original address is not changed through this method.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me please?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it's probably not possible, and I for one would argue that that's a good thing. You can use the "Reply-To" header if you want the mail client's reply to go to a specific address.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Treimin,

Sending mails as someone else may be a good learning exercise, but I hope you are aware that it is also illegal.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Treimin,

Sending mails as someone else may be a good learning exercise, but I hope you are aware that it is also illegal.


I need the technology only. It is illegal only if it is used for some illegal purposes. For your information, I found that there are lot of site using this technology. One of that is Zorpia.com, which is a community web site. Users of this web site can invite someone to there, through his Zopia account. In this case, Zopia will send an invitation email to the partner. If you check this mail, you can see that it was sent by the Zopia user's email id, even though Zopia doesn't know the password of his email account. Zopia is just a one site I've seen, but there are lot lot and lot of other sites..... oh another popular site is PayPal.

Since this is not a hacking technology, it's not illegal to do so.

Please help me on this.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Treimin,

I think you missed my point. I never implied, you were going to use it for illegal purposes.
As you rightly said, technology cannot be illegal/legal; it is the use of technology which can be legal/illegal.

All I was trying to say, is just be careful with the technology.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Treimin,

I think you missed my point. I never implied, you were going to use it for illegal purposes.
As you rightly said, technology cannot be illegal/legal; it is the use of technology which can be legal/illegal.

All I was trying to say, is just be careful with the technology.


I agree with you Maneesh.
Anyway, can you help me on this?
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you setting the "From" field using the java mail API? Can you post your code?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tested this with different methods. But nothing was succeeded.



This is how I set it. In this case, the mail displays "othersmail@mail.com" as the display name. But it also displays the original mail id too.

This is how it displays:
From: othersmail@mail.com<originalmail@mail.com>


I couldn't change the original mail id from it.

 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange.
I got a code like and it works for me.
Can you try using only one string instead of three and check out the result?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"othersmail@mail.com" doesn't look like a valid charset, does it? Check out the constructors of InternetAddress.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Strange.
I got a code like and it works for me.
Can you try using only one string instead of three and check out the result?


According the JavaDocs, this should be worked. But it doesn't work for me as I expected. I used a PasswordAuthentication object to get the Session object as below:



I think the problem is with the above code. Maneesh, is this the way how you get the Session object?
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nah.
I do not bother with the authenticator, I just pass null.
Did you read Rob's reply regarding charset?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Nah.
I do not bother with the authenticator, I just pass null.
Did you read Rob's reply regarding charset?



If you just pass 'null' for the getInstance method, where did you mention the username and password of your original mail? (I'm using Gmail SMTP server, with my Gmail account)?

The charset parameter which Rob mentioned is the third argument. I didn't pass it. I removed it.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never mention the user name/password and it works for me. My application uses my company Exchange server.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh!

This time, I just pass "null" to create the session object, and set my Gmail username and password as below:



This time, I'm getting AuthenticationFailedException on the transport.send(msg); statement. It was worked fine (but wan't appear the others mail id) before, when I pass the authentication details to the getInstance method, as I mentioned in my prior post.


 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do anyone know how to use Gmail for this purpose?
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh for your discovery.

But I've seen that before, and it is completely same as to what I've done already. It is able to send mails, but couldn't change the "From" field.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it looks like its a check put in by Google. From my company exchange server, I can send mails even from accounts who do not exist.

Is there any compelling reason you want to use gmail? Can you use some other SMTP server?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Is there any compelling reason you want to use gmail? Can you use some other SMTP server?


No reason for using Gmail. I can use any SMTP server, if I have any. But I couldn't find any free SMTP server.

Do you know about any free SMTP server provider, which I can use for this?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably easiest to run your own, assuming that you only want to send mails, not receive them. Apache James is written in Java, and could be embedded in your application, or you could use the Aspirin library (on dev.java.net).
 
Vikky Bhat
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Treimin,
Since you are using authenticator for gmail SMATP, it is not possible to set display name/id. it always takes the original id only. try some other SMTP like http://www.gmx.com . Hope this would help you.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gmx.com doesn't allow me to register.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Treimin,

just changing the "From:" field of you mails won't solve the problem that you have to log in with a valid username and password in order to be allowed to send mails. And IF you log in with a valid account it's very likely that Gmail (and probably other public mail providers) will override your setting with the data from your registered account. In fact it's possible to manipulate all email data depending on the configuration of a SMTP server. This is most probably the reason that the setFrom() method doesn't show any effect for you.

The only possibilities I see for your problem are to use a domain hosting service which allows you to register your domain AND configure arbitrary mail accounts at least for this domain or to set up a local SMTP relay server which will require a fixed IP and correct DNS entry as described in my other post. You could set up a local SMTP as well with a dynamic IP but then most public mail servers will still forbid you to relay mails to them.

What options do you have? A company SMTP relay? Extended domain services like free access to DNS and mail configuration? A fixed IP address?


Marco
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marco!

Neither options I have. However, the setFrom method in the above Gmail example changes the "Display Name".

I need to change both "Display Name" and the ID (address) too.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Treimin,

I'm sorry but I guess you don't have a way to change the real sender address as long as you have to use a public mail provider. Obviously your settings are overridden as soon as the Gmail server (and most probably other public servers, too) receives your mail. From the perspective of the mail providers this makes perfect sense though. Otherwise it would be possible to register just one official account and then send mails with arbitrary sender addresses via Gmail servers. Regarding spam mails this is surely not what Google wants and therefore it's forbidden or more exactly it's ignored by Gmail.

Depending on your requirements you could register Gmail accounts for all possible sender addresses. Of course this is not a very practical solution if you have many sender addresses or you don't even know the sender addresses your application will have to use.

If you can't manage to set up a real SMTP relay (with fixed IP and DNS) then the cheapest and easiest way is to register a domain with a domain hosting provider who allows you to freely configure mail settings. Then you're still stuck to a specific domain for all mails but at least - depending on the domain hoster - it could be possible to send emails with arbitrary "From:" fields in the form of "arbitrary.user@your-domain.org".

Alternatively you could register for a SMTP relay service which allows you send mails via their servers. Unfortunately I don't know such a service at all. Just search Google for "smtp relay service" and you will find many providers for such a service. As I said, I don't have real experiences with such a relay service so I can't give you recommendations but in any case I'm afraid you won't get this for free.

Marco
 
Paul Clapham
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Treimin Clark wrote:Thanks Marco!

Neither options I have. However, the setFrom method in the above Gmail example changes the "Display Name".

I need to change both "Display Name" and the ID (address) too.


Yeah, I'm not surprised that Gmail doesn't let you send e-mails claiming to come from "billgates@microsoft.com" (for example). That would be fraud and forgery (both of which are illegal in most places, contrary to what you seem to believe). Reputable servers won't let you send e-mails which claim to be from anybody outside their domains, at least. Just saying "but I need it for legal purposes" isn't going to change that situation.

You're also assuming that those sites which send e-mails on behalf of you (Zopia, Paypal) are sending the e-mails from their own servers. Are they? Hint: look at the e-mail headers to see where they are actually sent from. In fact you can get a lot of other information by looking at the headers. Also note that those sites have verified that the e-mail address you're sending from is actually one you have access to, right? When you register you have to respond to an e-mail, I would bet.

So, asking an SMTP server to send an e-mail which claims to be from some other unverified address isn't likely to work. That's a good thing really, no matter what these alleged "legal purposes" are.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
You're also assuming that those sites which send e-mails on behalf of you (Zopia, Paypal) are sending the e-mails from their own servers. Are they? Hint: look at the e-mail headers to see where they are actually sent from. In fact you can get a lot of other information by looking at the headers.


Please download and see the screenshot below.
gmail_screenshot.JPG
[Thumbnail for gmail_screenshot.JPG]
 
V Bel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using gmail and if you see the mailed by portion when you get a mail you will see a different server than the mailers domain.
So you can easily detect that this email is not the real one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic