之前写过一篇博文,通过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函数调用邮箱客户端发送邮件(可以带附件)的更多相关文章

  1. 利用Python+163邮箱授权码发送带附件的邮件

    背景 前段时间写了个自动爬虫的脚本,定时在阿里云服务器上执行,会从某个网站上爬取链接保存到txt文本中,但是脚本不够完善,我需要爬虫完毕之后通过邮件把附件给我发送过来,之前写过一个<利用Pyth ...

  2. JavaMail发送邮件、带附件邮件(完整版)

    工程目录如下: 1.准备javaMail需要的两个Jar包:mail.jar.activation.jar,然后add to build path 2.QQ邮箱开启SMTP服务,开启后,它会给你一串授 ...

  3. python发送邮件(带附件)

    python通过stmp发送qq邮件,带附件 import smtplib from email.mime.multipart import MIMEMultipart from email.mime ...

  4. CI框架发送邮件(带附件)

    最近写了一个发送带附件的邮件,发邮件挺简单的,在我这里最重要的是遇到问题,哈哈哈哈 1.主要方法看代码 public function send_mail(){ $this->load-> ...

  5. python webdriver firefox 登录126邮箱,先添加联系人,然后进入首页发送邮件,带附件。

    代码:#encoding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom ...

  6. Jmail发送邮件与带附件乱码解决办法

    Jamil发送邮件的具体用法: 首先,我们要从网上下载Jamil.dll的组件,这个网上很多,然后添加引用using jmail,然后再本机或者服务器上注册一下 将jmail.dll拷贝到服务器的sy ...

  7. Qt + CURL + mimetic 发送邮件(带附件)

    使用了大名鼎鼎的CURL 开源库,以及mimetic开源库. CURL支持N多协议.功能超强,但是不能直接发邮件附件,需要自己拼mime.太麻烦,于是乎~~ mimetic主要用于构造邮件mimeti ...

  8. nodejs——发送邮件(带附件)

    用到的包是 nodemailer,简单,有效. 1.auth 中的 pass,是指“邮箱第三方登录授权码”,如何获取授权码,以QQ邮箱为例,请点击:http://jingyan.baidu.com/a ...

  9. Go smtp发送邮件,带附件

    package main import ( "net/smtp" "bytes" "time" "io/ioutil" ...

随机推荐

  1. NewWord

    identification: 鉴定,识别; 验明; 身份证明; 认同; peer:PEER-TO-PEER:同等延迟机制.根据网络中共享资源方式的不同,局域网有两种组织形式 filters: n. ...

  2. LeetCode11.盛最多水的容器

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  3. repr()函数

    http://www.cnblogs.com/itdyb/p/5046415.html

  4. html5-figure和figcaption元素

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  5. Latex数学公式中的空格

    http://blog.sina.com.cn/s/blog_4ddef8f80100iwwv.html 两个quad空格 a \qquad b 两个m的宽度 quad空格 a \quad b 一个m ...

  6. Java基础语法(三)

    七.方法 定义: 方法就是完成特定功能的代码块 在很多语言里面都有函数的定义 函数在Java中被称为方法 格式: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2…) { 函数体; ...

  7. rt.jar sun package

          安装完JDK后,会在%JAVA_HOME% /jdk文件夹下生成一个src.zip,此文件夹对应rt.jar中的java源码,但细心研究后发现rt.jar中sun包下的文件不存在,也就是说 ...

  8. 【转】基于 Kylin 的推荐系统效果评价系统

    OLAP(联机分析处理)是数据仓库的主要应用之一,通过设计维度.度量,我们可以构建星型模型或雪花模型,生成数据多维立方体Cube,基于Cube可以做钻取.切片.旋转等多维分析操作.早在十年前,SQL ...

  9. arcgis desktop 地理编码服务发布

    1.创建地址定位器 2.创建复合地址定位器 3.鼠标右键,共享为,地理编码服务.

  10. brctl 命令详解

    安装网桥管理工具包:bridge-utile ```# yum install bridge-utils -y``` ```使用brctl命令创建网桥br1```# brctl addbr br1`` ...