VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)
之前写过一篇博文,通过MAPI实现调用邮箱客户端发送邮件带附件,当时对ShellExecute研究不深,以为ShellExecute不能带附件,因为项目需求原因(MAPI只能调用Foxmail和Outlook邮箱客户端,无法调用网易邮箱大师),不得不回头再次研究ShellExecute函数,最后发现ShellExecute可以完美调用Foxmail、网易邮箱大师、Outlook(单次发送只能添加一个附件)。因为我们安装完Foxmail、网易大师后,系统右键里发送到里有他们的快捷方式,所以就是在这里入手的,它们的快捷方式存放在系统路径下 C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\SendTo (这是我的电脑上的位置,具体根据当前系统登录用户目录下找)

Foxmail:
int SharedByFoxmail()
{
TCHAR szPath[MAX_PATH] = { };
SHGetSpecialFolderPath(NULL, szPath, CSIDL_SENDTO, FALSE);
CString strClient;
strClient.Format(L"%ls", szPath);
strClient += L"\\Foxmail.lnk";//拿到快捷方式的绝对路径 CString strRecv = “example@.com”;//收件人
CString FilePath = "\"C:\\Users\\Administrator\\Desktop\\123.txt\" \"C:\\Users\\Administrator\\Desktop\\image.png\"";//多个附件发送时 路径要用双引号括起来,路径之间用空格隔开 ShellExecute(NULL, L"open", strClient,FilePath, L"", SW_SHOW); //填写收件人
HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"TFoxComposeForm.UnicodeClass", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} HWND hChildWnd1 = NULL;
HWND hChildWnd2 = NULL;
HWND hChildWnd31 = NULL;
HWND hChildWnd32 = NULL;
HWND hChildWnd33 = NULL;
if (hWnd != NULL)
{
::SetForegroundWindow(hWnd); hChildWnd1 = ::FindWindowEx(hWnd, , L"TFoxComposeFrame.UnicodeClass", NULL);
hChildWnd2 = ::FindWindowEx(hChildWnd1, , L"TLayoutManager", NULL);
hChildWnd31 = ::FindWindowEx(hChildWnd2, , L"TFMZRichEdit.UnicodeClass", NULL);
//抄送
hChildWnd32 = ::FindWindowEx(hChildWnd2, hChildWnd31, L"TFMZRichEdit.UnicodeClass", NULL);
if (hChildWnd32 != NULL)
{
DWORD SelfThreadId = GetCurrentThreadId();//获取本身的线程ID
DWORD ForeThreadId = GetWindowThreadProcessId(hChildWnd32, NULL);//根据窗口句柄获取线程ID
AttachThreadInput(ForeThreadId, SelfThreadId, true);//附加线程 // WCHAR* szTest = L"comor_86sssss163.com";
//::SendMessage(hChildWnd32, WM_SETTEXT, 0, (LPARAM)strCC.GetBuffer(0));
//strCC.ReleaseBuffer();
} //收件人
hChildWnd33 = ::FindWindowEx(hChildWnd2, hChildWnd32, L"TFMZRichEdit.UnicodeClass", NULL);
if (hChildWnd33 != NULL)
{
DWORD SelfThreadId = GetCurrentThreadId();//获取本身的线程ID
DWORD ForeThreadId = GetWindowThreadProcessId(hChildWnd33, NULL);//根据窗口句柄获取线程ID
AttachThreadInput(ForeThreadId, SelfThreadId, true);//附加线程 // WCHAR* szTest = L"comor_86@163.com";
::SendMessage(hChildWnd33, WM_SETTEXT, , (LPARAM)strRecv.GetBuffer());
strRecv.ReleaseBuffer();
}
}
return 0;
}
网易邮箱大师:
int SharedByNetease()
{
TCHAR szPath[MAX_PATH] = { };
SHGetSpecialFolderPath(NULL, szPath, CSIDL_SENDTO, FALSE);
CString strClient;
strClient.Format(L"%ls", szPath);
strClient += L"\\Foxmail.lnk";//拿到快捷方式的绝对路径 CString strRecv = “example@.com”;//收件人
CString FilePath = "\"C:\\Users\\Administrator\\Desktop\\123.txt\" \"C:\\Users\\Administrator\\Desktop\\image.png\"";//多个附件发送时 路径要用双引号括起来,路径之间用空格隔开 ShellExecute(NULL, L"open", strClient,FilePath, L"", SW_SHOW); //填写收件人
HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"MailWriteWindow", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} ::SetForegroundWindow(hWnd); hWnd = NULL;
n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"MailWriteWindow", NULL);
n--;
} while (hWnd == NULL && n); if (hWnd == NULL)
{
return -;
} ::SendMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(, ));//模拟鼠标左键按下 Sleep(); SendKeys(strRecv);
return 0;
}
....................... ///////////////////////////////////////////////// void SendKeys(CString msg)
{
USES_CONVERSION;
wchar_t* data = T2W(msg.GetBuffer());
int len = wcslen(data); for (int i = ; i<len; i++)
{
SendUnicode(data[i]);
}
}
OutLook:
int SharedByOutlook()
{
CString strFile= "\"C:\\Users\\Administrator\\Desktop\\123.txt\""
CString strRecv= “example@.com”;//收件人 CString strPara;
strPara = "/a \"";
strPara += strFile;
strPara +="\"";//附件路径用双引号括起来,方式文件名中有空格造成调用失败 //获取outlook安装路径
CString strPath = ReadOutlookPath();
if (!strPath.IsEmpty())
{
//添加判断文件是否存在
if (PathFileExists(strPath + "outlook.exe"))
{
ShellExecute(NULL,L"open",L"outlook.exe",strPara,strPath,SW_SHOW);
}
} HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"rctrl_renwnd32", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} ::SetForegroundWindow(hWnd); TCHAR* szBuffer = strRecv.GetBuffer();
EnumChildWindows(hWnd, EnumChildWindowsProc, (LPARAM)szBuffer);
strRecv.ReleaseBuffer(); return ;
} ///////////////////////////////////////
CString CSharedHelper::ReadOutlookPath()
{
HKEY hKEY;
HKEY hKeyRoot = HKEY_LOCAL_MACHINE;
long ret = ::RegOpenKeyEx(hKeyRoot,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.EXE",
,
KEY_READ,
&hKEY);
if (ret != ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行
{
// AfxMessageBox(L"错误:无法打开有关的hKEY");
return L"";
} TCHAR Vals[MAX_PATH] = { };
DWORD keyType;
DWORD lenIt = MAX_PATH*sizeof(TCHAR);
if (::RegQueryValueEx(hKEY, L"Path", , &keyType, (BYTE*)Vals, &lenIt) != ERROR_SUCCESS)
{
// AfxMessageBox(L"错误:RegQueryValueExA错误");
return L"";
} CString str;
str.Format(L"%ls", Vals);
return str;
} BOOL CALLBACK CSharedHelper::EnumChildWindowsProc(HWND hWnd, LPARAM lParam)
{
HWND EditNumHwnd = ::FindWindowEx(hWnd, NULL, _T("RichEdit20WPT"), NULL);
if (EditNumHwnd != NULL)
{
if (::GetWindowLong(EditNumHwnd, GWL_STYLE)&WS_VISIBLE)
{
TCHAR* str = (TCHAR*)lParam;
//::SendMessage(EditNumHwnd, WM_CHAR, WPARAM('a'), 0);//发送一个字消息
::SendMessage(EditNumHwnd, WM_SETTEXT, , (LPARAM)str); return ;
}
} return ;
}
VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)的更多相关文章
- 利用Python+163邮箱授权码发送带附件的邮件
背景 前段时间写了个自动爬虫的脚本,定时在阿里云服务器上执行,会从某个网站上爬取链接保存到txt文本中,但是脚本不够完善,我需要爬虫完毕之后通过邮件把附件给我发送过来,之前写过一个<利用Pyth ...
- JavaMail发送邮件、带附件邮件(完整版)
工程目录如下: 1.准备javaMail需要的两个Jar包:mail.jar.activation.jar,然后add to build path 2.QQ邮箱开启SMTP服务,开启后,它会给你一串授 ...
- python发送邮件(带附件)
python通过stmp发送qq邮件,带附件 import smtplib from email.mime.multipart import MIMEMultipart from email.mime ...
- CI框架发送邮件(带附件)
最近写了一个发送带附件的邮件,发邮件挺简单的,在我这里最重要的是遇到问题,哈哈哈哈 1.主要方法看代码 public function send_mail(){ $this->load-> ...
- python webdriver firefox 登录126邮箱,先添加联系人,然后进入首页发送邮件,带附件。
代码:#encoding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom ...
- Jmail发送邮件与带附件乱码解决办法
Jamil发送邮件的具体用法: 首先,我们要从网上下载Jamil.dll的组件,这个网上很多,然后添加引用using jmail,然后再本机或者服务器上注册一下 将jmail.dll拷贝到服务器的sy ...
- Qt + CURL + mimetic 发送邮件(带附件)
使用了大名鼎鼎的CURL 开源库,以及mimetic开源库. CURL支持N多协议.功能超强,但是不能直接发邮件附件,需要自己拼mime.太麻烦,于是乎~~ mimetic主要用于构造邮件mimeti ...
- nodejs——发送邮件(带附件)
用到的包是 nodemailer,简单,有效. 1.auth 中的 pass,是指“邮箱第三方登录授权码”,如何获取授权码,以QQ邮箱为例,请点击:http://jingyan.baidu.com/a ...
- Go smtp发送邮件,带附件
package main import ( "net/smtp" "bytes" "time" "io/ioutil" ...
随机推荐
- redis 知识点
默认端口 6379 单个value 最大可以保存1G 默认RDB(异步刷盘方式) 禁用持久化修改redis.conf,找到save配置,改为save "" 即可 1. 特点 Re ...
- 使用js调用js
直接上源码: <div class="choose"> choose a mode<br> <hr> <button type=" ...
- django 1.9.7 css控制模板样式
问题:css样式不能控制html样式(针对开发环境,不针对生产环境) 现象: django.template.exceptions.TemplateSyntaxError: Invalid block ...
- yum 与 apt 的对比
一.概念 使用yum/apt之前,你很可能会遇到配置源(ubuntu下一般内置的就比较好,所以可能很少人手动配置),那这个源是什么呢,就是告诉apt/yum,安装软件的时候你要从哪里下载.比如你使用1 ...
- 关于git上的一些错误信息
如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 提示出错信息:fatal: remote ...
- 转:C#线程系列讲座(1) BeginInvoke和EndInvoke方法
转载自:http://www.cnblogs.com/levin9/articles/2319248.html 开发语言:C#3.0IDE:Visual Studio 2008本系列教程主要包括如下内 ...
- 转:C# 小数位数保留的方法集锦
转载自:http://www.jb51.net/article/17010.htm 1. System.Globalization.NumberFormatInfo provider = new Sy ...
- 第三方统计分析埋点工具对比,神策、Ptmind、GrowingIO、国双,还有谷歌分析,谁更好?
第三方统计分析埋点工具对比,神策.Ptmind.GrowingIO.国双,还有谷歌分析,谁更好?https://www.colabug.com/2985393.html GA.Mixpanel 和神策 ...
- tensorflow serving
1.安装tensorflow serving 1.1确保当前环境已经安装并可运行tensorflow 从github上下载源码 git clone --recurse-submodules https ...
- Doing Homework HDU - 1074
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...