Using Exchange Web Services v1 to retrieve emails from a generic mailbox? - c#

I am using Exchange Web Services v1 to pull down unread emails from a user's mailbox like so:
//get exchange service
ExchangeServiceBinding exchangeService = new ExchangeServiceBinding();
exchangeService.Credentials = credentials; //LAN credentials of user
exchangeService.Url = URL; // http://myserver.com/ews/exchange.asmx
//REturn all properties
FindItemType findType = new FindItemType();
findType.Traversal = ItemQueryTraversalType.Shallow;
findType.ItemShape = new ItemResponseShapeType();
findType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
//Only search the inbox
DistinguishedFolderIdType[] foldersToSearch = new DistinguishedFolderIdType[1];
foldersToSearch[0] = new DistinguishedFolderIdType();
foldersToSearch[0].Id = DistinguishedFolderIdNameType.inbox;
findType.ParentFolderIds = foldersToSearch;
//Only unread emails
RestrictionType restriction = new RestrictionType();
IsEqualToType isEqualTo = new IsEqualToType();
PathToUnindexedFieldType pathToFieldType = new PathToUnindexedFieldType();
pathToFieldType.FieldURI = UnindexedFieldURIType.messageIsRead;
//Not IsRead
FieldURIOrConstantType constantType = new FieldURIOrConstantType();
ConstantValueType constantValueType = new ConstantValueType();
constantValueType.Value = "0";
constantType.Item = constantValueType;
isEqualTo.Item = pathToFieldType;
isEqualTo.FieldURIOrConstant = constantType;
restriction.Item = isEqualTo;
findType.Restriction = restriction;
FindItemResponseType findResponse = exchangeService.FindItem(findType);
ResponseMessageType[] responseMessType = findResponse.ResponseMessages.Items;
List<ItemIdType> unreadItemIds = new List<ItemIdType>();
Now I would like to find emails from a generic mailbox.
How would I go about specifying the mailbox I would like to pull emails from?

Related

Exchange Web Services - Create Tasks

I've been trying to create some code to generate non-recurring tasks in EWS. I've followed this link, unfortunately, the code to actually send the task wasn't presented. I then followed this Office Dev Center link which everyone seems to reference.
However, CreateItemType() isn't recognised.
Here's my code so far:
const string o365Server = "myO365Domain";
const string targetMailId = "myemail#test.com";
var service = new ExchangeService();
var task = new Task(service);
string itemId = null;
task.Subject = "mySubject";
task.Body = new MessageBody {BodyType = BodyType.Text, Text = "my new task"};
task.StartDate = DateTime.Now;
var createItemRequest = new CreateItemType();
createItemRequest.Items = new NonEmptyArrayOfAllItemsType();
createItemRequest.Items.Items = new ItemType[1];
createItemRequest.Items.Items[0] = task;
I've installed Microsoft Exchange WebServices 2.2.0 via Nuget and
using Microsoft.Exchange.WebServices.Data;
I just want to be able to send tasks to individual email accounts in our O365 domain. Any help would be appreciated.
Dim clientTZService As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2010)
clientTZService.Credentials = New NetworkCredential(userEmail, userPass)
clientTZService.AutodiscoverUrl(userEmail, AddressOf RedirectionCallBack)
' Create the task
Dim Task1 As Task = New Task(clientTZService)
Task1.Subject = "New Task"
Task1.Body = New MessageBody(String.Format("test"))
Task1.StartDate = DateTime.Now
Dim DueDate As DateTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 2)
Task1.DueDate = DueDate
Task1.Save(New FolderId(WellKnownFolderName.Tasks, "test#domain.com"))

paypal sandbox test account in windows form application in C# for POS credit card swipe

I create sample a windows form application.
I download pay pal sdk in visual studio.
I create paypal sandbox test account
whre to add the credential details?
where we put app id:
Sandbox test AppID:
APP-80W284485P519543T
I have copy some code for winform app while click a button that is.
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
accessToken = new OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd", "EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", sdkConfig).GetAccessToken();
HttpContext CurrContext = HttpContext.Current;
APIContext apiContext = new APIContext(accessToken);
Item item = new Item();
item.name = _ItemDescription;
item.currency = "USD";
item.price = _Amount;
item.quantity = "1";
item.sku = _UPC;
List<Item> itms = new List<Item>();
itms.Add(item);
ItemList itemList = new ItemList();
itemList.items = itms;
Address billingAddress = new Address();
billingAddress.city = "Chennai";
billingAddress.country_code = "US";
billingAddress.line1 = "11/12";
billingAddress.line2 = "Andavar nager main street";
billingAddress.postal_code = "600089";
billingAddress.state = "Tamil nadu";
CreditCard crdtCard = new CreditCard();
crdtCard.billing_address = billingAddress;
crdtCard.cvv2 = 2222;
crdtCard.expire_month = 4;
crdtCard.expire_year = 2020;
crdtCard.first_name = "Arul";
crdtCard.last_name = "Murugan";
crdtCard.number = "4032039053301695";
crdtCard.type = "visa";
Details details = new Details();
details.tax = "0";
details.shipping = "0";
details.subtotal = _Amount;
Amount amont = new Amount();
amont.currency = "USD";
amont.total = _Amount;
amont.details = details;
Transaction tran = new Transaction();
tran.amount = amont;
tran.description = _ItemDescription;
tran.item_list = itemList;
List<Transaction> transactions = new List<Transaction>();
transactions.Add(tran);
FundingInstrument fundInstrument = new FundingInstrument();
fundInstrument.credit_card = crdtCard;
List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
fundingInstrumentList.Add(fundInstrument);
PayerInfo pi = new PayerInfo();
pi.email = "sysumurugan-facilitator#gmail.com";
pi.first_name = "Arul";
pi.last_name = "Murugan";
Payer payr = new Payer();
payr.funding_instruments = fundingInstrumentList;
payr.payment_method = "credit_card";
payr.payer_info = pi;
pi.shipping_address = new ShippingAddress
{
city = "San Mateo",
country_code = "US",
line1 = "SO TEST",
line2 = "",
postal_code = "94002",
state = "CA",
};
Payment paymnt = new Payment();
paymnt.intent = "sale";
paymnt.payer = payr;
paymnt.transactions = transactions;
try
{
Payment createdPayment = paymnt.Create(apiContext);
CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
}
catch (PayPal.Exception.PayPalException ex)
{
if (ex.InnerException is PayPal.Exception.ConnectionException)
{
CurrContext.Response.Write(((PayPal.Exception.ConnectionException)ex.InnerException).Response);
}
else
{
CurrContext.Response.Write(ex.Message);
}
}
catch (Exception es)
{
MessageBox.Show( es.ToString());
}
CurrContext.Items.Add("RequestJson", JObject.Parse(paymnt.ConvertToJson()).ToString(Formatting.Indented));
my reference link is
http://pastebin.com/H7VuPQs4
Parsing a PayPal REST Credit Card Transaction Response (JSON),
C# PayPal REST API Checkout with Credit Card
please explian to me any other way for credit card transaction for POS(Point Of Sale) through win form application.
The PayPal .NET SDK is meant for server applications (e.g. ASP.NET) where application credentials are stored in a secure manner. Using the SDK directly from a WinForms application running on a POS system presents a security risk because your merchant account credentials are not stored in a secure manner. Ideally, the POS system should be communicating back to a secure server somewhere that performs the processing.
With that said, this use case is what PayPal Here is designed for.

C# EWS copy contacts to a mailbox

I want to select the user "test" so I can create a contact into his mailbox.
My actual problem is that it will create Contacts into my user "c-sharp".
"c-sharp" has full access on "test" mailbox
I changed the IP and the contact infos users are also only for testing.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.EnableScpLookup = false;
service.Credentials = new WebCredentials("c-sharp", "c-sharp", "domain");
service.UseDefaultCredentials = false;
IgnoreBadCertificates();
service.Url = new Uri("https://192.000.000.000/EWS/Exchange.asmx");
Contact contact = new Contact(service);
// Specify the name and how the contact should be filed.
contact.GivenName = "n.a.";
contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
contact.DisplayName = "bau gmbh";
// Specify the company name.
contact.CompanyName = "bau";
// Specify the business, home, and car phone numbers.
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "00000 00000";
contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "n.a.";
contact.PhoneNumbers[PhoneNumberKey.BusinessFax] = "00000 00000";
// Specify two email addresses.
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress("e#mail.de");
//homepage
contact.BusinessHomePage = "n.a.";
// Specify the home address.
PhysicalAddressEntry paEntry1 = new PhysicalAddressEntry();
paEntry1.Street = "straße";
paEntry1.City = "stadt";
paEntry1.State = "D";
paEntry1.PostalCode = "88890";
paEntry1.CountryOrRegion = "Deutschland";
contact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry1;
contact.Save();
Already tried this:
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test");
I tested it with "test" and "test#domain" and "test#domain.de"
And get back this error:
"Der Name des Identitätsprinzipals ist ungültig."
Own translation: "The name of the identity principal is unvailed"
You can use Impersonation like this
ExchangeUserData exchangeUserData = new ExchangeUserData();
exchangeUserData.Username = "c-sharp";
exchangeUserData.Password = "c-sharp"; // c-sharp's Password
ExchangeService service = Service.ConnectToServiceWithImpersonation(exchangeUserData, impersonatedUserPrincipal);
Contact contact = new Contact(service);
// Specify the name and how the contact should be filed.
contact.GivenName = "n.a.";
contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
contact.DisplayName = "bau gmbh";
// Specify the company name.
contact.CompanyName = "bau";
// Specify the business, home, and car phone numbers.
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "00000 00000";
contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "n.a.";
contact.PhoneNumbers[PhoneNumberKey.BusinessFax] = "00000 00000";
// Specify two email addresses.
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress("e#mail.de");
//homepage
contact.BusinessHomePage = "n.a.";
// Specify the home address.
PhysicalAddressEntry paEntry1 = new PhysicalAddressEntry();
paEntry1.Street = "straße";
paEntry1.City = "stadt";
paEntry1.State = "D";
paEntry1.PostalCode = "88890";
paEntry1.CountryOrRegion = "Deutschland";
contact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry1;
contact.Save();
If your c-sharp user has the proper rights in Exchange, you should be able to do:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials("c-sharp", "c-sharp", "domain");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test");
If this doesn't work for you, please comment below or update your question (there's an "edit" link under it) with the exact behavior you are seeing including any error messages.
Problem sloved.
I found the bug... both of you are right just change:
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "test");
Into:
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "test#domain.de");
Thats all ...
Great thanks to you

Why aren't I getting email notifications from eBay API?

I am trying to get an email when one of my items sell. However, no email ever comes. If I change it to notify me when an item is listed, that email arrives so I know my code is somewhat working. Here is my code:
ApiContext apiContext= GetApiContext();
SetNotificationPreferencesCall apiCall = new SetNotificationPreferencesCall(apiContext);
ApplicationDeliveryPreferencesType applicationDeliveryPreferences = new ApplicationDeliveryPreferencesType();
applicationDeliveryPreferences.ApplicationEnable = EnableCodeType.Enable;
applicationDeliveryPreferences.ApplicationEnableSpecified = true;
applicationDeliveryPreferences.ApplicationURL = "mailto://myemail#gmail.com";
applicationDeliveryPreferences.AlertEmail = "mailto://myemail#gmail.com";
applicationDeliveryPreferences.AlertEnable = EnableCodeType.Enable;
applicationDeliveryPreferences.AlertEnableSpecified = true;
NotificationEnableType notification =
new NotificationEnableType
{
EventEnable = EnableCodeType.Enable,
EventEnableSpecified = true,
EventType = NotificationEventTypeCodeType.ItemSold,
EventTypeSpecified = true
};
apiCall.UserDeliveryPreferenceList = new NotificationEnableTypeCollection(new[] { notification });
apiCall.ApplicationDeliveryPreferences = applicationDeliveryPreferences;
apiCall.UserDeliveryPreferenceList = new NotificationEnableTypeCollection(new[] { notification });
apiCall.Execute();

How to send emails to newsletter subscribers using mail chimp in asp.net?

I am using the below code to send email to newsletter subscribers in website, but this code does not seems to work, can anyone guide me, how to integrate mail chimp in asp.net website: -
listSubscribe cmd = new listSubscribe();
listSubscribeParms newlistSubscribeParms = new listSubscribeParms
{
apikey = apikey,
id = "1",
email_address = "test#gmail.com",
merge_vars = new Dictionary<string, object>(),
double_optin = false,
email_type = EnumValues.emailType.html,
replace_interests = true,
send_welcome = false,
update_existing = true
};
listSubscribeInput newlistSubscribeInput = new listSubscribeInput(newlistSubscribeParms);
var subscribeSuccess = cmd.Execute(newlistSubscribeInput);

Categories

Resources