I need to send a message to client email address.Client mail id was
ssteph9220#gmail.com.
I never need to give a client email address in output.I need to
give that client email address as static.
ContactFragment.java:
view.findViewById(R.id.textView10).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
String name=edit1.getText().toString();
String e_mail = edit2.getText().toString();
String subject = edit3.getText().toString();
String message = edit4.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, e_mail);
i.putExtra(Intent.EXTRA_TEXT, name);
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, message);
//i.setType("message/rfc822");
i.setData(Uri.parse("mailto:"+"ssteph9220#gmail.com")); -->Client Email address for an example
//startActivity(Intent.createChooser(i, "Choose an Email client :"));
}
});
So far I done a code like these.Finally the message was send
successfully.
But I check that email address.The message wasn't received.Anybody
can help me with these.Thank you.
If you are using mailto:, you need to use ACTION_SENDTO, not ACTION_SEND.
Beyond that, the user must send the email -- all ACTION_SEND and ACTION_SENDTO will do is set up the message in the user's email app's "composer".
Related
This question already has answers here:
send data to email in background
(3 answers)
Closed 6 years ago.
i was creating Android Intent Mail. i am getting all the subject, to , mail body in email. is there is any possibility to send the mail without pressing send button .
My code is :
public void Sendmail(HashMap s) {
HashMap<String, String> sss = s;
String[] toppings = new String[sss.size()];
int size1 = 0;
for (String key : sss.keySet()) {
toppings[size1] = key + "\n" + sss.get(key) + "\n";
System.out.println("key: " + key + " value: " + sss.get(key));
size1++;
}
StringBuilder builder = new StringBuilder();
for (String s3 : toppings) {
builder.append(s3);
}
String mbody = builder.toString();
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("plain/text");
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Task Activity");
i.putExtra(android.content.Intent.EXTRA_TEXT, mbody);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"hari.andoidsaiss#gmail.com"});
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Main2Activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
You can't do it. A user should know what he is sending. Also a user should be aware about his actions.
You can do it using API and sending Email from server.
You can't do it with Share Intent of Android as it will populate installed app from your device which can process your data.
You can achieve this by following ways:
Implement mail client to send emails from your server side. ex: mailgun.
Integrate API's like Javamail or Gmail to your android app to get your work done.
I am developing an android app. In my android app I am having feed back form. and I take a email id from user as input. and i want when a user clicks on submit button the email should send.
I dont want that user should add his/her password for that.
I have checked the default method by Intent and the second method in the below link ..
Second Method
If you want the email to be sent from the account of the user of the app, a proper authentication would be required.
As a result, either you could send an intent to email app (as you mentioned) or you could do it yourself (as in second method mentioned by you).
But the second method obviously requires password since you are sending an email on behalf of the user (from their account). Gmail (or any mail service provider as a matter of fact) won't allow that without a password.
So to answer your question in a nutshell, no. You can not do it without a password.
In stead, you could use a work around. You can send all emails sent through your apps from a single mail id (which is created by you so you know the password). Now in the content of the email, you can store the email id of the user from whom you are asking for the feedback.
This way, you just have to ask for the mail id (no password) and you also get their contact information if you want to contact them back.
Hope this helps.
Good luck.
I had the same question and found a solution that I modified to work for me. You can do a search in stack overflow but solution I used was from sending email without using defaut my token was being retrieved after the email was sent out. Anyway here is snippet of a working sample I created.
I imported the following jars:
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
I had the following permission requests
<uses-permission android:name="android.permission.GET_ACCOUNTS">
</uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"> </uses-permission>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Also for my scenario I asked the user for their user account. If you know it then you can skip this step. the snippet I have for this can be done another way using helper methods provided by studio libs however I just did it via a dialog.
public Account[] getGoogleAccounts(){
return accounts = acctManager.getAccountsByType("com.google"); }
public void getGoogleAccountsDialog(){
if( getGoogleAccounts().length>1) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Select Google Account:")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setItems(convertAccountTo(getGoogleAccounts()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setSelectedAcct(accounts[which]);
initToken(activity);
dialog.dismiss();
}
});
builder.create();
builder.show();
}
else if(getGoogleAccounts().length==1){
setSelectedAcct(getGoogleAccounts()[0]);
}
else{
Toast.makeText(context,"No google account(s) exists on this device.",Toast.LENGTH_LONG);
}
}'
because this is a working sample i just have dummy text setup to fire the email immediately after the name is selected. However you will modify this code for you suiting.
Was the token is obtained I send the email request which is the getAndUseAuthTokenInAsynTask()
public void initToken(Activity ctx) {
acctManager.getAuthToken(getSelectedAcct(), "oauth2:https://mail.google.com/", null, activity, new AccountManagerCallback<Bundle>(){
#Override
public void run(AccountManagerFuture<Bundle> result){
try{
Bundle bundle = result.getResult();
token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
getAndUseAuthTokenInAsyncTask();
Log.d("initToken callback", "token="+token);
} catch (Exception e){
Log.d("test", e.getMessage());
}
}
}, null);
}
lastly the remainder of the calls
public synchronized void sendMail
(String subject, String body, String user,
String oauthToken, String recipients)
{ try {
SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com", 587,
user, oauthToken, true);
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(
body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(user));
message.setSubject(subject);
message.setDataHandler(handler);
if (recipients.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(recipients));
smtpTransport.sendMessage(message, message.getAllRecipients());
} catch (Exception e) {
Log.d("test", e.getMessage(), e);
}
}
public SMTPTransport connectToSmtp(String host, int port, String userEmail,
String oauthToken, boolean debug) throws Exception {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "false");
session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
final String emptyPassword = null;
transport.connect(host, port, userEmail, emptyPassword);
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1",
userEmail, token).getBytes();
response = BASE64EncoderStream.encode(response);
transport.issueCommand("AUTH XOAUTH2 " + new String(response), 235);
return transport;
}
Hope this helps someone else. Keep in mind that the sending of the mail should not be done on the main thread.
Not sure if useful to you, but have you considered also using the built-in email functionality? This wouldn't even require the user to enter their user id nor password, but of course they'll leave your app to the email client to send the email.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"recipient#email.com", "",};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sample mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a sample mail..");
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send mail client :"));
(Btw: This would show many other apps along the email clients. If you're interested in such a solution, I can post some code to filter out all apps but email clients)
Hello Friends i wan to make editable false in all edittext when i send mail by my application
programmatically
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","test#mymail.com, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Message);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
finish();
friends my question is i want Text Subject Feild and Text/Body feild Read Only user can not edited it's value so how can i make it any idae?
your passing a intent to android device to handle mailing function specifying to handle it once intent is passed it will be handle by gmail or any other email client installed in your phone once they handle and get your data that is subject and message your application will be in paused state i mean to say you don't have control over other applications that handles your data.
create your mail handling and sending mail instead of passing it as intent
set editable false works only when you have those edit fields inside your application not in other activities that are started by your intent
You can create you own email sending activity without passing intent to any native email client app.There you can easily disable the editText for message and subject. The code for sending email is:
public class SendMail{
public static void main(String[] args) {
final String username = "username#gmail.com";
final String password = "password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from-email#gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to-email#gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
taken from here
Basically if you choose email chooser of android to send an email you lost all the control over this intent. So overriding these behaviour is very hard and might be not possible. So overcoming on this issue you can follow this link Sending Email in Android using JavaMail API without using the default/built-in app.
You can find how to use the javamail Api as in the above link.
Now you can make your own layout for mail activity. And you can use
youreditetxtWhichyouwanttodisable.setEditable(false);
This might be useful.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to add new line to email contents?
I want to send an email in the following format:
name: name
email: email
address: address
But when I send the mail, it is received as follows:
NameEmailAddress
How can I insert a new line between these?
my code is
private void sendEMail(String message) {
AppSheredPref pref = new AppSheredPref(this);
String supplierEmailId = pref.getSupplierEmailId();
String loggedIn = pref.getLoggedInEmailId();
//String to = supplierEmailId;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{loggedIn,supplierEmailId});
//email.putExtra(Intent.EXTRA_CC, new String[]{ to});
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, "App Finance");
email.putExtra(Intent.EXTRA_TEXT, message);
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
Try this it might help you.
email.putExtra(Intent.EXTRA_SUBJECT, "App Finance");
email.putExtra(Intent.EXTRA_TEXT,"Name:. XYZ \n\nemail:xyz#gmail.com\n\nAddress:XYZ");
If your body content is HTML, then you need to use < /br>
And if your body content is simple TEXT then you need to use simply \n
Hope it will help you.
There are two methods to solve this issue.
1) Use StringBuilder for that
StringBuilder sb;
sb.append("Name : ");
sb.append('\n');
sb.append("Email : ");
sb.append('\n');
sb.append("Address : ");
mInEmail.putExtra(android.content.Intent.EXTRA_TEXT,sb);
2) Use Html.fromHtml(StringValue) for that
String str = "Name:- <br></br> Email:- <br></br> Address:- <br></br>";
mInEmail.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(str));
it will solve your problem.
I am new to android programming.
I got my app with Gmail account sends emails.
What I need now is how to receive new emails from G mail?
Or at least how to get a notification that there is a new mail in my inbox?
I don't want to use Gmail app from market or embedded email android app or so...I'm making my own app that manages Gmail accounts (like some kind of widget in my own app).
In order to implement this functionality ,first you need to establish the connection with the gmail server,then you need to check the inbox folder for new messages. If find then send the notification to the user using NotificationManager. please follow this links http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android and another link is
Sending Email in Android using JavaMail API without using the default/built-in app
Try this:
Properties props = new Properties();
//IMAPS protocol
props.setProperty(“mail.store.protocol”, “imaps”);
//Set host address
props.setProperty(“mail.imaps.host”, imaps.gmail.com);
//Set specified port
props.setProperty(“mail.imaps.port”, “993″);
//Using SSL
props.setProperty(“mail.imaps.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”);
props.setProperty(“mail.imaps.socketFactory.fallback”, “false”);
//Setting IMAP session
Session imapSession = Session.getInstance(props);
Store store = imapSession.getStore(“imaps”);
//Connect to server by sending username and password.
//Example mailServer = imap.gmail.com, username = abc, password = abc
store.connect(mailServer, account.username, account.password);
//Get all mails in Inbox Forlder
inbox = store.getFolder(“Inbox”);
inbox.open(Folder.READ_ONLY);
//Return result to array of message
Message[] result = inbox.getMessages();
You need to first grant permission to "Notification accept " so your app can receive any notifications from device apps.
You need to follow the steps below to enable the "Notification accept" permission:
Setting => Apps => Special access => Notification accept
You need to give your application permission in AndroidManifest.xml:
<service android:name="com.secondclone.UINotificationService"
android:label="#string/app_name_notification"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"
/>
</intent-filter>
</service>
Then, you write down the conditions to only receive notifications for new email notifications
/* This is the class that helps you receive notifications when there are new emails */
public class UINotificationService extends NotificationListenerService {
#Override
public void onCreate()
{
super.onCreate();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn)
{
// Get notification of new messages of the Gmail app com.google.android.gm
if (sbn.getPackageName().equals("com.google.android.gm"))
{
/* What you need to handle when a new email is here */
Bundle extras = sbn.getNotification().extras;
if (!contentGmail.equals(extras.getCharSequence("android.bigText").toString()))
{
contentGmail = Objects.requireNonNull(extras.getCharSequence("android.bigText")).toString();
// This is the recipient's Gmail name information.
String mreceiver = extras.getString("android.subText");
// This is the sender's name.
String mSender = extras.getString("android.title");
// This is the Email subject.
String mSubject = Objects.requireNonNull(extras.getCharSequence("android.text")).toString();
// This is the text of this new mail.
String mContent = Objects.requireNonNull(extras.getCharSequence("android.bigText")).toString();
//Notification.EXTRA_TEXT
time = sbn.getPostTime() / 1000;
Log.i("tsMail", "Sender = " + mSender + " Receiver= " + receiver + " Content Gmail= " + mContent );
}
}
}
}
#Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg","Notification Removed");
}
}