Send Email in CRM using a Template (SendEmailFromTemplateRequest)


Hi using the following code we can send an email programmatically that uses the email-template withing CRM

Suppose you have created a web application and have a button named btnSendEmail over there.

Put the following code in it’s event handler

protected void btnSendEmail_Click(object sender, EventArgs e)

{

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.AuthenticationType = 0; // AD ( On-Premise)

token.OrganizationName = “nameofyourorganization”;

CrmService myService = new CrmService();

myService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myService.CrmAuthenticationTokenValue = token;

// Create an instance of email

email myEmail = new email();

//set the owner of the mail

myEmail.ownerid = new Owner();

myEmail.ownerid.type = EntityName.systemuser.ToString();

myEmail.ownerid.Value = new Guid(“26063267-7B85-DD11-B2E0-00164145E126”);

// specify the from part of the email

activityparty from = new activityparty();

from.partyid = new Lookup();

from.partyid.type = EntityName.systemuser.ToString();

// guid of the system user who is sending the mail

from.partyid.Value = new Guid(“24543267-7B85-DD11-B2E0-00164145E126”);

myEmail.from = new activityparty[] { from };

// specify the to part of the email

activityparty to = new activityparty();

to.partyid = new Lookup();

to.partyid.type = EntityName.systemuser.ToString();

to.partyid.Value = new Guid(“26063267-7B85-DD11-B2E0-00164145E126”);

myEmail.to = new activityparty[] { to };

TargetSendFromTemplateEmail myTargetSendFromTemplateEmail = new TargetSendFromTemplateEmail();

myTargetSendFromTemplateEmail.Email = myEmail;

SendEmailFromTemplateRequest mySendEmailFromTmpRequest = new SendEmailFromTemplateRequest();

// Specify entity instance id for RegardingID

mySendEmailFromTmpRequest.RegardingId = new Guid(“132C847E-028A-DD11-8E7E-00164145E126”);

// Specify the type of entity

mySendEmailFromTmpRequest.RegardingType = EntityName.opportunity.ToString();

// Specify the email instance to be sent

mySendEmailFromTmpRequest.Target = myTargetSendFromTemplateEmail;

// Specify the template to be used ( Either a global or created specfially for that entity)

mySendEmailFromTmpRequest.TemplateId = new Guid(“6963788F-048A-DD11-8E7E-00164145E126”);

SendEmailFromTemplateResponse mySendEmailFromTmpResponse =(SendEmailFromTemplateResponse)                                  myService.Execute(mySendEmailFromTmpRequest);

}

Bye….

This message has not yet been submitted for delivery (email activity status pending send)


Hi,

I was writing a custom code to send email using templates in CRM 4.0.

The code was working properly but the mails weren’t getting sent.

Checking at activities in CRM i found out the email activities have got created but were showing the status as “job pending”.

While searching for the same i found out that making modification to this file

C:\Program Files\Microsoft CRM Email\Service\Microsoft.Crm.Tools.EmailAgent.xml

would solve this problem.

Especially these tags !!

<MaxMessageCount>30</MaxMessageCount>

<PendingStatusDelay>30</PendingStatusDelay>
<SendingStatusDelay>60</SendingStatusDelay>

Check this link for detailed information

Email router configuration XML file explained

and this post as well

http://niths.wordpress.com/2008/08/27/this-message-has-not-yet-been-submitted-for-delivery/

http://msdn.microsoft.com/en-us/library/cc906237.aspx

http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?pg=2&p=1&tid=8e427cc6-f88a-4a56-b2c3-321418398718&dg=microsoft.public.crm

Bye

CRM Customization Import failed Error: Invalid name prefix


Hi,

While importing customization from development to staging server we were receiving the error.

It was giving the error on a particular relationship “opportunity_new_dataaudit”.

What we did was to comment the entire EntityRelationShip tag for that particular relationship along with it’s corresponding EntityMap entry in the customization.xml

i.e.

<EntityRelationship Name=”Opportunity_New_DataAudit“>
<EntityRelationshipType>OneToMany</EntityRelationshipType>
<ReferencingEntityName>New_DataAudit</ReferencingEntityName>
<ReferencedEntityName>Opportunity</ReferencedEntityName>
<CascadeAssign>NoCascade</CascadeAssign>
<CascadeDelete>RemoveLink</CascadeDelete>
<CascadeReparent>NoCascade</CascadeReparent>
<CascadeShare>NoCascade</CascadeShare>
<CascadeUnshare>NoCascade</CascadeUnshare>
<ReferencingAttributeName>new_opportunityid</ReferencingAttributeName>
<RelationshipDescription>
<Descriptions>
<Description description=”Unique identifier for Opportunity associated with Data Audit.” languagecode=”1033″ />
</Descriptions>
</RelationshipDescription>
<field name=”new_opportunityid” requiredlevel=”none” imemode=”auto” lookupstyle=”single” lookupbrowse=”0″>
<displaynames>
<displayname description=”Opportunity” languagecode=”1033″ />
</displaynames>
</field>
<EntityRelationshipRoles>
<EntityRelationshipRole>
<NavPaneDisplayOption>UseCollectionName</NavPaneDisplayOption>
<NavPaneArea>Details</NavPaneArea>
<NavPaneOrder>10000</NavPaneOrder>
</EntityRelationshipRole>
</EntityRelationshipRoles>
</EntityRelationship>

AND

<EntityMap>
<EntitySource>opportunity</EntitySource>
<EntityTarget>new_dataaudit</EntityTarget>
<AttributeMaps />
</EntityMap>
<EntityMap>

And than we tried importing it and it worked for us.

And there was another way we were able to resolve this error, quite interestingly when we changed the name of EntityRelationship from

Opportunity_New_DataAudit

to

new_Opportunity_New_DataAudit
<EntityRelationship Name=”new_Opportunity_New_DataAudit“>
<EntityRelationshipType>OneToMany</EntityRelationshipType>
<ReferencingEntityName>New_DataAudit</ReferencingEntityName>

i.e simply appending new_ to relationship name in the customization.xml it imported successfully !

Bye…

Specifying user id and password in application defination file for BDC


Hi,

To specify connection string with user id and password we need to have the following things in the application defination file (.xml)

<?xml version=1.0?>

<LobSystem xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:schemaLocation=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog BDCMetadata.XSD Type=Database Version=1.0.0.0 Name=NorthwindLOBSystem xmlns=http://schemas.microsoft.com/office/2006/03/BusinessDataCatalog>

<Properties>

<Property Name=WildcardCharacter Type=System.String>%</Property>

</Properties>

<LobSystemInstances>

<LobSystemInstance Name=NorthwindInstance>

<Properties>

<Property Name=DatabaseAccessProvider Type=System.String>SqlServer</Property>

<Property Name=AuthenticationMode Type=System.String>PassThrough</Property>

<Property Name=RdbConnection Data Source Type=System.String>d-2926</Property>

<Property Name=RdbConnection Integrated Security Type=System.String />

<Property Name=RdbConnection Initial Catalog Type=System.String>Northwind</Property>

<Property Name=RdbConnection User ID Type=System.String>sa</Property>

<Property Name=RdbConnection Password Type=System.String>sa</Property>

<Property Name=RdbConnection Pooling Type=System.String>false</Property>

</Properties>

</LobSystemInstance>

</LobSystemInstances>

<Entities>

We need not to specify any value for Integrated Security as we are using sql authentication

And can specify user id and password with RdbConnection User ID and Password Property.

Bye…

Using SQL backup and restore for MOSS


Hi,

  • Back Up and Restore the content database to a new Sql server
  • In Central Administration page
  • Go to Application Management and Click on Create or extend web application.
  • Therein Create a new web application. Once application is created don’t create Site Collection.
  • Now again go back to Application Management.
  • Therein click Content Databases
  • Change the web application to point to web application you just created.
  • Remove the default content database created while creating the web application.
  • Then click on Add a content database
  • Specify the Database Server where the content database was restored and in database name specify the name of the content database.
  • The site should get restored properly.

Check out this good information

http://blah.winsmarts.com/2007-10-Backup_and_Restore_Strategies_in_MOSS_2007.aspx

Bye

(Service Unavailable) Could not load all ISAPI filters for site/service. Therefore startup aborted.


Hi,

After running the Sharepoint products and technologies configuration wizard successfully, the central administration site page opens up.

( We were installing MOSS 2007 on 64 bit machine)

But in my case it was giving the following error

“Service Unavailable”

Checking into event log gave the following information

Could not load all ISAPI filters for site/service. Therefore startup aborted.

and

ISAPI Filter ‘C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll’ could not be loaded due to a configuration problem. The current configuration only supports loading images built for a AMD64 processor architecture. The data field contains the error number. To learn more about this issue, including how to troubleshooting this kind of processor architecture mismatch error, see http://go.microsoft.com/fwlink/?LinkId=29349.

Searching for it the solution that I found was the following

// Disabling the 32bit mode for your web site.

cscript C:\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0

and then the following

// Registering ASP.NET 2.0 as the default framework for that web site

C:\Windows\Microsoft.NET\Framework64\v2.0.50727>
aspnet_regiis.exe -i

This resolved the issue for us!!

Bye…

Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

Skip to content ↓