AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 18.09.2010, 22:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
dynamic-ax.co.uk: Sending Emails from Dynamics AX without Outlook.
Источник: http://dynamic-ax.spaces.live.com/Bl...4DE3!320.entry
==============


People often ask me if Outlook is necessary to send email from Dynamics AX, and my answer is.. Yes! ‘Out Of the Box’, Dynamics AX does need Outlook installed on the same machine as the AX client to send out emails.
However Dynamics AX can very easily be customized to send out standard reports via email, without outlook. We are talking about a really small modification here, there is only one method that needs to be edited, hence for clients that find outlook to be too expensive to fit their budget or if there are architectural issues (for example, installing outlook on Terminal Server),this code could be a life saver...
Note: AX – Outlook integration is confined to email, there are many other benefits of using outlook with dynamics ax, such as synchronization of crm contacts, transferring appointment to outlook calendar, etc. If the client chooses not to install outlook with Dynamics AX, then the company would be loose out on all these features.
Anyways.. this is what you need to do:
The following method is used to send emails from Dynamics AX:
Class\Info\Method\ReportSendMail
Out of the box, AX uses the class SysInetMail, which invokes the user email profile to find the outlook / email client that is being used on the system, obviously if it doesn’t find out it would throw an error.
There are 2 (possibly more, but 2 that I know of) other ways to send out mails from ax (easily).
1. Microsoft.CDO Com Object – Collaboration Data Objects can be used to send email and it comes pre installed on all AX supported versions of Windows.. as a matter of fact the emails generated by Alerts use the class SysMailer, which in turn uses a CDO object.
2. System.Net.Mail Assembly – In this example I choose to this path, simply because of the flexibility of the API.. Note: for this to work System.Net should be a part of the Ax References (AOT > References) ...by default it always is one of AX references, but there is no harm is double checking.
Here is the code... Note: in order to use this code one needs to agree to these Terms.
//
// ##/##/###
// Mohammed
//
// Email out of ax withot outlook.
// the default ax code uses inet to send email and the sysInetMail class check the users profiles for a outlook account.
// changing code to use System.Net.Mail assembly
//
//
void reportSendMail(PrintJobSettings p1)
{
//Mohammed : Start Declaration
//SysINetMail m = new SysINetMail(); // Mo : Commented out old AX code
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.Attachment attachment;
System.Net.Mail.AttachmentCollection attachementCollection;
System.Net.Mail.SmtpClient myMail;
System.Net.Mail.MailAddress mailFrom;
System.Net.Mail.MailAddress mailTo;
str userMailAddress;
str receiverMailAddress;
str mailBody;
str smtpServer;
fileNameOpen fileNameForEmail;
str mail;
FileIOPermission perm;
userinfo userInfo;
//end Declaration
str fileName = 'axaptareport';
;
if (p1.format() == PrintFormat::ASCII)
fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999)+'TXT'; // Mo : NL
//fileName = fileName + '.txt'; // Mo Commented this line
else if (p1.format() == PrintFormat::RTF)
fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999)+'RTF';
//fileName = fileName + '.rtf';
else if (p1.format() == PrintFormat::HTML)
fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999)+'HTM';
//fileName = fileName + '.htm';
//else if (p1.format() == PrintFormat::PDF) // Mohammed :Performance Testing : commentign this line and replacing the line below.
else if (p1.format() == PrintFormat::PDF || p1.format() == PrintFormat::PDF_EMBED_FONTS)// Mohammed :Performance Testing :(replacing the above line) addign this line as it was present in the jsRemotecontroller project.. can be removedd later..
fileNameForEmail = subStr(p1.fileName(),strLen(p1.fileName())-3,-999)+'PDF';
//fileName = fileName + '.pdf';
//Mohammed : Start Logic
mail = subStr(fileNameforEmail,(strlen(fileNameforEmail)-8),9);
select firstonly name from userInfo where userInfo.id == SysuserInfo::find().Id; // to find the user name
fileNameforEmail = winApi::getTempPath() + mail; // store attachment in a temp location
perm = new FileIOPermission(fileNameforEmail,'w');
if(!perm)
{
throw error("Cannot move attachment to temp location.");
return;
}
try
{
perm.assert();
}
catch
{
throw error("Cannot gain access to Temp location.");
return;
}
userMailAddress = SysUserInfo::find().Email; // find current users email address setup up in user //options
receiverMailAddress = p1.mailTo();
mailFrom = new System.Net.Mail.MailAddress(userMailAddress,userInfo.name);
mailTo = new System.Net.Mail.MailAddress(receiverMailAddress,"");
mailBody = "Email sent from " + CompanyInfo::name() + ", using Dynamics AX";
smtpServer = SysEmaiLParameters::find(false).SMTPRelayServerName;// using the SMTP server ip //setup in email Parameters
mailMessage = new System.Net.Mail.MailMessage(mailFrom,mailTo);
mailmessage.set_Subject(p1.mailSubject());
mailmessage.set_Body(mailBody);
//move attachment file to Temp folder
winapi::moveFile(p1.fileName(), fileNameforEmail);
attachementCollection = mailMessage.get_Attachments();
attachment = new System.Net.Mail.Attachment(fileNameforEmail);
attachementCollection.Add(attachment);
myMail = new System.Net.Mail.SmtpClient(smtpServer);
mymail.Send(mailmessage);
winApi::deleteFile(fileNameforEmail); // delete temp file
CodeAccessPermission::revertAssert();
// Mohammed end
}
I hope this code is of use to you.
Thanks for reading..  

Technorati Tags: Dynamics AX,Email Without Outlook,Mohammed Rasheed


Источник: http://dynamic-ax.spaces.live.com/Bl...4DE3!320.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
За это сообщение автора поблагодарили: Ivanhoe (0).
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
CRM DE LA CREME! Configuring Microsoft Dynamics CRM 4.0 for Internet-facing deployment Blog bot Dynamics CRM: Blogs 0 18.08.2009 11:05
gatesasbait: Dynamics AX 2009 SSRS and SSAS Integration Tips Blog bot DAX Blogs 3 09.07.2009 13:07
dynamic-ax.co.uk: Import Emails from Outlook 2007 into Dynamics AX 2009 Blog bot DAX Blogs 1 03.07.2009 07:17
dynamic-ax.co.uk: Dynamics AX : Send Alerts (email) to Multiple Users – Mohammed Rasheed Blog bot DAX Blogs 0 03.07.2009 07:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 14:01.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.