0

Hi I was following the answer to this question:

Sending Email in Android using JavaMail API without using the default/built-in app but setting the sender in the method sendMail does not work.

I would like to be able to send mail from different addresses such as support@example.com, sales@example.com, etc... so that way when people reply to the emails they go to the correct addresses.

Edit: By does not work I mean whenever I get an email it is always from the account that you sign into using:

GMailSender sender = new GMailSender("username@gmail.com", "password");

and not the sender field that you fill out in the sendMail method:

sender.sendMail("This is Subject",   
                        "This is Body",   
                        "sender@gmail.com",   
                        "recipiant@yahoo.com");   
Vlad Davidchenko
  • 454
  • 1
  • 7
  • 24
Navetz
  • 393
  • 1
  • 2
  • 12

2 Answers2

0

What do you mean "does not work"? If you don't provide full details, no-one can help you.

The chances are that the SMTP mail server you are using is blocking you from spoofing email addresses you do not own, and for good reason. It sounds like you are writing an app that will do things the user probably does not want it to do.

Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • There are many reasons to do something like this and most of them are totally fine. Furthermore, most SMTP server DO accept such mail, especially if you are authorized and the sender email belongs to the same domain as your usual one. – IanH Dec 16 '11 at 19:53
  • When people do certain things using my app I want to automatically send an email notifications to certain people based on what they are doing in my app. I want to be able to change who the sender was so when/if they reply the correct person gets the reply emails. – Navetz Dec 16 '11 at 21:54
  • 1
    @Navetz If you take this approach each user will need to provide email account details (SMTP server hostname, username & password) and in most cases that will work. you may get requests for support tho, as some people will struggle with that process. It would be better to build a server application, pass the information via a REST API, and then have your app server use a single SMTP server to send the emails out. – Ollie C Dec 19 '11 at 10:29
0

You should have your own email server set up for this. It will direct the email through your server, which will send the email under whatever email alias you like. That way the details will not be "incorrect" because the user should have an account with you which is logged into your server to send the email.

Ozzy
  • 8,244
  • 7
  • 55
  • 95