vba - 如何使用 SenderEmailAddress 检查收到的电子邮件?
问题描述
我有一个循环来检查来自 Joe Doe 的带有特定主题的传入电子邮件。该循环有效并保存了来自 Joe Doe 的附件。
If (Msg.SenderName = "Doe, Joe") And _
(Msg.Subject = "Test: Smartsheet") And _
(Msg.Attachments.Count >= 1) Then
我想使用 SenderEmailAddress 而不是 SenderName。
I tested below codes:
If (Msg.SenderEmailAddress = "test@noreplay.com") And _
(Msg.Subject = "Test: Smartsheet") And _
(Msg.Attachments.Count >= 1) Then
和
If (SenderEmailAddress = "test@noreplay.com") And _
(Msg.Subject = "Test: Smartsheet") And _
(Msg.Attachments.Count >= 1) Then
解决方案
第二段新代码肯定行不通,因为SenderEmailAddress
它是Msg
.
要Msg.SenderEmailAddress = "test@noreplay.com"
返回True
必须完全匹配。“Test@noreplay.com”或“test@NoReplay.com”或任何其他此类变体将不会返回True
。
建议一:
恢复原始代码但添加额外语句
If (Msg.SenderName = "Doe, Joe") And _
(Msg.Subject = "Test: Smartsheet") And _
(Msg.Attachments.Count >= 1) Then
Debug.Print Msg.SenderEmailAddress
运行宏后,即时窗口将包含 Joe Doe 电子邮件的发件人电子邮件地址列表,以便您检查它们是否符合您的预期。
建议二:
使比较不区分大小写,因此:
If (LCase(Msg.SenderEmailAddress) = "test@noreplay.com") And _
(Msg.Subject = "Test: Smartsheet") And _
(Msg.Attachments.Count >= 1) Then
推荐阅读
- freemarker - 在 Freemarker 中更改输出日期格式,而与输入格式无关
- hyperledger-fabric - 连接客户端peer失败,请检查配置和peer状态
- swift - 快速格式化时间(iOS)
- php - 用php检测png图像的背景颜色是否为灰色
- mongodb - 将 mongodb 4.0 与 robomongo 连接
- r - If lattice in function
- r - 如何在 R 中将值列表 (x,y,value) 转换为 2D 矩阵
- python - Kivy ui 在 RPI 上非常慢
- siebel - 可以在 siebel 清单中添加 2 个 PR
- sql - 嵌套 CASE 表达式