Smack Multi user chat set answer XMPPError: bad-request-cancel - xmpp

I developed android chat app by using XMPP server (prosody) and smack library. When I trying to create chat room, the room is created successfully, but when I send configuration Form this error is appears:
XMPPError: bad-request - cancel
My Code:
EntityBareJid entityBareJid = null;
entityBareJid = JidCreate.entityBareFrom("room5#conference.MyServiceName.com");
MultiUserChat muc = multiUserChatManager.getMultiUserChat(entityBareJid);
muc.join(Resourcepart.from("rshRoom5"));
Log.d("GROUP" , "Room now is created ...... ");
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(answerForm);
And this is the muc component in server configuration file:
Component "conference.MyServiceName.com" "muc"
name = "chatrooms server"
restrict_room_creation = false;

Related

Smack - get entry starts with specific letter

I'm using Smack to build simple XMPP android client, I need to retrieve users only starts with letter "a" I've tried to use roster and UserSearchManager both need specific user id I couldn't use wild card for e.g.
UserSearch userSearch = new UserSearch();
answerForm.setAnswer("user", "a*");
or
RosterEntry entry = roster.getEntry("a*");
Any help?
This is a working snippet:
public static List<Row> searchOnServerForUsers(String searchString, XmppManager xmppManager) throws Exception
{
UserSearchManager usersearchManager = new UserSearchManager(abstractXMPPConnection.getConnection());
String searchServiceName = XmppConstants.USER_SERVICE_NAME_PREFIX + abstractXMPPConnection.getConnection().getServiceName();
Form form = usersearchManager.getSearchForm( searchServiceName );
Form answers = form.createAnswerForm();
answers.setAnswer("Name", false);
answers.setAnswer("Email", false);
answers.setAnswer("Username", true);
// answers.setAnswer("search", "*"); //search for all registered users
answers.setAnswer("search", "a*"); //your search string
ReportedData data = usersearchManager.getSearchResults(answers, searchServiceName);
List<Row> rows = data.getRows();
return rows;
}
So you have to use UserSearch,
on each column (like Username, pay attention to case!)
you have to set if search (true) or to not search (false)
your search string (in your usecase: "a*")
Don't use smack version 4.4.0 alpha1 it has some bugs. After reverting it to 4.1.1 . I got all the users. from UserSearchManager

How to send screenshot to any mail recipient using selenium

How can I send any screenshot captured using selenium web driver to a mail recipient?
In c# you can use
using Outlook1=Microsoft.Office.Interop.Outlook;
Add reference of Above
Outlook1.Application outlookApp1 = new Outlook1.Application();
Outlook1.MailItem mailItem = (Outlook1.MailItem)outlookApp1.CreateItem(Outlook1.OlItemType.olMailItem);
outlookApp1.CreateItem(Outlook1.OlItemType.olMailItem);
mailItem.Subject = "Your subject";
mailItem.To = "Email id";
mailItem.Importance = Outlook1.OlImportance.olImportanceLow;
mailItem.Display(false);
mailItem.Send();
You can even add attachments

how to create persistent muc room in smack 4.1 beta2

migrated from asmack to smack 4.1 beta2.
The muc rooms created are no longer persistent.
MultiUserChatManager mucm=MultiUserChatManager.getInstanceFor(connection);
muc=mucm.getMultiUserChat(groupid+"#conference.localhost");
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.createOrJoin(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage();
when created with gajim, the rooms are persistent.
EDIT : Here is code we used earlier. By default the chat rooms were persistent,
muc = new MultiUserChat(connection, groupid+"#conference.localhost");
if(!muc.isJoined())
{
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.join(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage(0);
}
You need to submit form like this for making a persistent group:
private void setConfig(MultiUserChat multiUserChat) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
You need to set muc#roomconfig_persistentroom to true in the MUC configuration from when creating the room.
MultiuserChat muc = manager.getMultiUserChat("myroom#muc.example.org");
muc.create("myNick");
// room is now created by locked
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(answerForm);
// sending the configuration form unlocks the room
Note that not all XMPP MUC services support persistent rooms. For more information see:
https://www.igniterealtime.org/builds/smack/dailybuilds/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#create(java.lang.String)
https://www.igniterealtime.org/builds/smack/dailybuilds/documentation/extensions/muc.html
http://xmpp.org/extensions/xep-0045.html#createroom
In smack 4.1.1, The answers given by #saurabh dixit throw an exception. Please check this thread on ignite website Correct implementation for persistent rooms smack 4.1.1
multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
multiUserChat = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(roomJID));
multiUserChat.create(Resourcepart.from(nickname));
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
submitForm.getField("muc#roomconfig_enablelogging").addValue("1");
submitForm.getField("x-muc#roomconfig_reservednick").addValue("0");
submitForm.getField("x-muc#roomconfig_canchangenick").addValue("0");
submitForm.getField("x-muc#roomconfig_registration").addValue("0");
submitForm.getField("muc#roomconfig_passwordprotectedroom").addValue("0");
submitForm.getField("muc#roomconfig_roomname").addValue(roomName);
submitForm.getField("muc#roomconfig_whois").addValue("participants");
submitForm.getField("muc#roomconfig_membersonly").addValue("1");
submitForm.getField("muc#roomconfig_persistentroom").addValue("1");
multiUserChat.sendConfigurationForm(submitForm);
This is how you can send the room configuration from and configure room.
For more Details please see question.
How to send room configuration form and create persistce rooms from android using smack 4.3.4

Is it possible to import/export sms/mms on Blackberry10?

Is it possible to import/export sms/mms on Blackberry10 programmatically using cascades API??
SMS actually uses the same API as other messages (like email). The key difference is that you want to pick the SMS account specifically, and you probably want to build is as part of a conversation.
Using the Message part of the BlackBerry PIM API, try something like this:
MessageService messageService;
AccountService accountService;
//Get the SMS/MMS account
QList<Account> accountList = accountService.accounts(Service::Messages,"sms-mms");
AccountKey accountId = accountList.first().id();
// Create a contact to whom you want to send sms/mms. Put the right phone number in yourself
int contactKey = -1;
MessageContact recipient = MessageContact(contactKey, MessageContact::To,"5555555555", "5555555555");
//Create a conversation because sms/mms chats most of the time is a conversation
ConversationBuilder* conversationBuilder = ConversationBuilder::create();
conversationBuilder->accountId(accountId);
QList<MessageContact> participants;
participants.append(recipient);
conversationBuilder->participants(participants);
Conversation conversation = *conversationBuilder;
ConversationKey conversationId = messageService.save(accountId, conversation);
//Create a message Builder for sms/mms
MessageBuilder* messageBuilder = MessageBuilder::create(accountId);
messageBuilder->addRecipient(recipient);
// SMS API's handle body as an attachment.
QString body = "body of the sms";
messageBuilder->addAttachment(Attachment("text/plain","body.txt",body));
messageBuilder->conversationId(conversationId);
Message message;
message = *messageBuilder;
//Sending SMS/MMS
MessageKey key = messageService.send(accountId, message);
qDebug() << "+++++++ Message sent" << endl;`

Java send mail - how to use "Send via"

We are sending mails from our local system.
We got our IPs white listed.
We have a scenario where we have to send email on behalf of somebody.
for ex: our email id is: support#mycompany.com
but we need to send email with a from address: john#abc.com
When we send with different from address, the receiving mail client displays "phishing" error.
One of the solution is to use "via" as dispayed in google link
https://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=185812
We also want the message to be displayed like this in receivers inbox.
Any pointers in this will help us a lot.
thanks in advance.
Note: We are using localhost as the smtp.
Read about email headers. you can add email headers while creating the mail message at runtime.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
for further reading check this :
http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/package-summary.html
#http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/MimeMessage.html
You can create aliases for the smtp server too.