Does MT support SMTP SendMail, or am I stuck with MFMailComposeViewController? Right now, I have it working (MFMailComposeViewController), but when I add an attachment, the mail is not received by the receipient.
I was wondering if SMTP would be more reliable and handle attachments.
Yes, it is supported its under System.Net.Mail but it is not recommended to be used because there is no way to get the user credentials from the system unless you ask for them on your application but i dont know if its against the EULA of apple.
i have successfully sent email with attachments from the iphone using the following code hope this helps :)
MFMailComposeViewController _mail;
mailButton.TouchUpInside += (o, e) =>
{
byte[] data = File.ReadAllBytes("photo.png");
NSData datas = NSData.FromArray(data);
if (MFMailComposeViewController.CanSendMail)
{
_mail = new MFMailComposeViewController ();
_mail.SetMessageBody ("This is the body of the email", false);
_mail.AddAttachmentData(datas, "image/png", "photo.png");
_mail.Finished += delegate(object sender, MFComposeResultEventArgs e1)
{
if (e1.Result == MFMailComposeResult.Sent)
{
UIAlertView alert = new UIAlertView ("Mail Alert", "Mail Sent", null, "Success", null);
alert.Show ();
//you should handle other values that could be returned in e.Result and also in e.Error
}
e1.Controller.DismissModalViewControllerAnimated (true);
};
this.PresentModalViewController (_mail, true);
} else {
//handle not being able to send mail
}
};
Also here is the link to the test solution, its based on mike bluestein's example http://dl.dropbox.com/u/2058130/MailDemo.zip and it works for me :)
hope this helps
Alex
Whether it supports it or not, you shouldn't use it.
You have no way of getting the user's SMTP connection settings, so you cannot send mail as the user.
You cannot assume that the user's connection can connect to your server.
Related
I've started using the GMail API and it's working fine on my local machine; it will open the Google permissions page and I can select my account. It then stores the return json token and only asks again if this token is removed.
When I publish to the server, the OAUTH page is never displayed and the application appears to timeout with a 'Thread was being aborted' exception.
My code;
try
{
using (var stream = new FileStream(HttpContext.Current.Server.MapPath("~/credentials/client_id.json"), FileMode.Open, FileAccess.Read))
{
string credPath = HttpContext.Current.Server.MapPath("~/credentials/gmail_readonly_token.json");
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
db.writeLog("INFO", "Gmail Credentials Saved","Credential file saved to: " + credPath);
}
// Create Gmail API service.
service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credential,
});
}
catch (Exception e)
{
db.writeLog("Error", "Failure when creating Gmail class", e.Message, null, _username, null);
}
Is there something I need to change within the 'client_id.json' (formally client_secret.json) file? The only thing I have altered is the redirect_uris line.
Any other suggestions would be welcome, the only other question I could find that is similar is here but there is no answer.
Thanks,
Danny.
The first one worked because you followed the intended use case, which is client-side. But, to implement authorization on the server, follow the Implementing Server-Side AUthorization guide.
m having an issue with Office 365 EWS (its only Office 365, Exchange 2010 and 2013 work fine). I can create my pull subscription without error but when I go to use it by calling
getEvents()
I receive an error:
ErrorNoRespondingCASInDestinationSite
The following error occured while retrieving events for exchange
resource: - Exchange Web Services are not currently
available for this request because none of the Client Access Servers
in the destination site could process the request.
Here is some code snippets
Using autodiscover and setting up credentials
this.exchangeService.Credentials = new NetworkCredential(this.Username, this.Password);
try {
this.exchangeService.AutodiscoverUrl(this.Username, RedirectionCallback);
}
catch(Exception ex)
{
Logger.WriteToEventLog(EventLogEntryType.Warning, 104, "ExchangeDataAccess, AutodiscoverURL error: " + ex.Message);
}
if (exchangeService.Url == null)
{
this.ExchangeServerURL = GetOffice365EWSUrl(this.Username);
this.exchangeService.Url = new Uri(this.ExchangeServerURL);
this.exchangeService.CookieContainer = new CookieContainer();
}
Afterwhich we Login and find our exchange user that we will perform all operations under
ServicePointManager.ServerCertificateValidationCallback = (sender1, certificate, chain, errors) => true;
string username = this.Username;
if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
{
username = this.Username.Remove(this.Username.IndexOf("#"));
}
NameResolutionCollection resolveNameResult = this.exchangeService.ResolveName(username, ResolveNameSearchLocation.ContactsThenDirectory, true);
if (resolveNameResult.Count() > 0)
{
roomEmailAddress = resolveNameResult[0].Mailbox.Address;
if (!string.IsNullOrEmpty(roomEmailAddress))
{
this.ExchangeUserEmailAddress = roomEmailAddress;
logMsg.AppendLine("Logged into Exchange with " + roomEmailAddress + " successfully, RetrieveRoomsList is next");
}
}
We then get a SubscribeResponse and save it to a list
subscribeResponse = this.exchangeDataAccess.ExchangeSubscribe(syncPoint.ThirdPartyId, syncPoint.Watermark, true);
We pass the above object into a wrapper method to get all Events from the EWS
Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null;
GetEventsResults eventsResults = subscription.GetEvents();
if (eventsResults == null || eventsResults.ItemEvents.Count() == 0) {
return mailboxEvents;
}
mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
mailboxEvents.Add(subscription, eventsResults.ItemEvents);
return mailboxEvents;
The line that calls subscription.GetEvents() is where the exception indicated at the top is returned.
There is another layer of complexity added on because our Exchange user has a domain name of #FOOlab.onmicrosoft.com where as all of the rooms being managed have a domain name of #LAB.FOO.COM
According to the customer this is ADFS authentication, however I really don't know much about it.
I can say however that this code base did work (got events) and then something seemed to change and the error started popping up. Originally I thought the customer changed something but we have tested this against another Office 365 (without ADFS) and saw the same error, so now I don't know what to think.
The links below can explain it far better then I can, but what I have done so far which has resolved my issue is to surround the GetEvents
with the add and removal of the header data X-AnchorMailbox
MSDN Link1 Link2
public Dictionary<PullSubscription, IEnumerable<ItemEvent>> GetEvents(SyncPoint syncpoint)
{
Dictionary<PullSubscription, IEnumerable<ItemEvent>> mailboxEvents = null;
if (this.authenticateContext.GetExchangeServerVersion().Contains("365"))
{
try
{
//this is to maintain affinity (see here https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx)
//it was added to fix an error: The following error occured while retrieving events for exchange resource: <room address> - Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request.
//according to docs it is only when getting notifications that its important
if (this.exchangeService.HttpHeaders.Any(m => m.Key.Equals("X-AnchorMailbox")))
{
this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
}
this.exchangeService.HttpHeaders.Add("X-AnchorMailbox", syncpoint.ThirdPartyId); //this is the email address of the mailbox being queried
}
catch { }
}
GetEventsResults eventsResults = syncpoint.pullSubscription.GetEvents();
if (eventsResults == null || eventsResults.ItemEvents.Count() == 0)
{
return mailboxEvents;
}
mailboxEvents = new Dictionary<PullSubscription, IEnumerable<ItemEvent>>();
mailboxEvents.Add(syncpoint.pullSubscription, eventsResults.ItemEvents);
try
{
this.exchangeService.HttpHeaders.Remove("X-AnchorMailbox");
} catch { }
return mailboxEvents;
}
I want to ask I have developed a mobile application which you can login using Facebook username and password so I want to know how can I save the username and password from Facebook into my remote database.
This is my code any help please:
var fb = require('facebook'); fb.appid = "281158112043247";
// Set the URL
fb.permissions = ['email'];
fb.authorize();
fb.addEventListener('login', function(e) {
if (e.success) {
fb.requestWithGraphPath('me', {}, 'GET', function(e) {
if (e.success) {
var data= JSON.parse(e.result);
xhr = Titanium.Network.createHTTPClient();
xhr.open("Post", "http://192.168.131.145:5220/Create.svc/createClient");
var params = {
Clientusername: data.name,
//password:password1.value,
// Clientpassword: Ti.Utils.md5HexDigest(password1.value),
Clientnom: data.name,
Clientid:data.id,
Clientemail: data.email
};
xhr.send(JSON.stringify(params));
//xhr.send(e.result);
Ti.API.info("Name:"+data.name);
Ti.API.info("email:"+data.email);
Ti.API.info("facebook Id:"+data.id);
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response.');
}
});// request graph
}else{
if(e.error){
alert(e.error);
}else{
alert("Unkown error while trying to login to facebook.");
}
}
});
You don't have access to their Facebook password. The oauth specifically protects against you having to know their access credentials. It allows Facebook to separately identify you, and what you are doing with the API. The user can also then disable your access to their data, if they see fit. But if you had their password, you could do anything that they can do, even temporarily steal their account. Plus their account would only be as secure as your storage of their password (is it encrypted? are you servers secure? on premise? compromised? running any malware?). So generally, no, it's a bad idea, don't do that, even if you figure out a way to do so.
In the case of your code above, you have already authorized the user inside your app, so you won't need to authorize them again. They'll already be logged in. You should check if (fb.loggedIn) and then do your logged-in-only code, else fb.authorize();.
I'm currently writing an Exchange 2007 Transport Agent to replace some headers in all outgoing mails from a particular sender. I managed to replace the 'From' SMTP header successfully, but rewriting the 'Return-Path' header does not seem to work.
To make this all happen, I have written a custom SmtpReceiveAgent and subscribe to the OnEndOfData event like this:
private static void MyAgent_OnEndOfData(ReceiveMessageEventSource source, EndOfDataEventArgs e)
{
try
{
var address = e.MailItem.Message.From.SmtpAddress;
if (address.ToLower().EndsWith("[internal email domain]"))
{
// replace the From: header - WORKING FINE!
e.MailItem.Message.From = new EmailRecipient("[displayname]",
"[email address]");
// replace the Return-Path: header - NOT WORKING!
var headerList = e.MailItem.Message.RootPart.Headers;
var header = (AddressHeader)headerList.FindFirst("Return-Path");
var newheader = new AddressHeader("Return-Path") { Value = "[email address" };
headerList.ReplaceChild(newheader, header);
}
}
catch (Exception ex)
{
// do something useful here
}
}
Per the RFCs, the Return-Path header is supposed to be set by the recipient's SMTP server. If a Return-Path header exists in the email, it is to be removed, and reset by the recipient's server.
Maybe what you are seeing, is the correct implementation of the RFCs.
I'm not sure, but it sounds like you might want to be changing the "reply-to" header and not "return-path". "return-path" is meant to be set by the server.
I have created a pretty basic Flash website for a client and am having an issue programming a Client Login feature that he would like. Currently, if I navigate to the site and click Client Login, it takes me to a login page. The way I need this to work is -- within the Flash, using ActionScript 2.0 -- have the user enter their UserID and Password and click to login, which submits POST vars to the form action of the Client Login website.
Is this possible/legal to do from a different domain? How would I go about doing this, assuming it's possible?
Try this:
myVars = new LoadVars();
myVars.username = username.text;
myVars.password = pwd.text;
myVars.onLoad = function(success) {
trace("yay!");
else {
trace("try again");
}
}
myVars.sendAndLoad("login.php", myVars, "POST");
So, I get "yay!" with the code provided below (yours had an error in it). However, I need to be redirected to the resulting "logged-in" page. How do I do that?
myVars = new LoadVars();
myVars.txtUserID = "some_user";
myVars.txtPassword = "some_password";
myVars.__VIEWSTATE = "dDw3MTcxMTg3ODM7dDw7bDxpPDM+O2k8NT47PjtsPHQ8cDxsPFRleHQ7PjtsPGRlbW87Pj47Oz47dDw7bDxpPDE+O2k8Mz47aTw1Pjs+O2w8dDxwPGw8VGV4dDs+O2w8YmFja2dyb3VuZC1jb2xvcjojZjZmNmY2XDtjb2xvcjojMzMzMzMzXDs7Pj47Oz47dDxwPDtwPGw8c3R5bGU7PjtsPHdpZHRoOjEwMHB4XDs7Pj4+Ozs+O3Q8cDw7cDxsPHN0eWxlOz47bDx3aWR0aDoxMDBweFw7Oz4+Pjs7Pjs+Pjs+Pjs+56k0UDxn5ED61lGLjP0fIkStm6o=";
myVars.onLoad = function(success) {
if (success)
{
trace("yay!");
} else {
trace("try again");
}
}
myVars.sendAndLoad("http://www.buildertrend.net/loginFrame.aspx?builderID=35&bgcolor=%23f6f6f6&fcolor=%23333333&uwidth=100&pwidth=100", myVars, "POST");