.netSMTP发送Email实例(可带附件)
实例 发送 email 附件
2023-06-13 09:15:02 时间
publicstaticvoidsendEmail(stringtoAddress,stringemailbody)
{
varfromAddress=ConfigurationManager.AppSettings["EmailAddress"];
stringfromPassword=ConfigurationManager.AppSettings["EmailPassword"].ToString();
conststringsubject="JobRecommendation";
varsmtp=newSmtpClient
{
Host=ConfigurationManager.AppSettings["SmtpServer"].ToString(),
Port=int.Parse(ConfigurationManager.AppSettings["SmtpPort"]),
EnableSsl=true,
DeliveryMethod=SmtpDeliveryMethod.Network,
UseDefaultCredentials=false,
Credentials=newNetworkCredential(fromAddress,fromPassword)
};
using(varmessage=newMailMessage(fromAddress,toAddress,subject,HttpUtility.HtmlEncode(emailbody)))
{
smtp.Send(message);
}
}
<addkey="EmailAddress"value="**********@gmail.com"/>//EmailAddress
<addkey="EmailPassword"value="*********"/>//EmialPWD
<addkey="SmtpServer"value="smtp.gmail.com"/>
<addkey="SmtpPort"value="587"/>
<--带附件版本->
varfromAddress="allenyinj@gmail.com";
stringfromPassword="yj1989120";
conststringsubject="CV";
varsmtp=newSmtpClient
{
Host="smtp.gmail.com",
Port=587,
EnableSsl=true,
DeliveryMethod=SmtpDeliveryMethod.Network,
UseDefaultCredentials=false,
Credentials=newNetworkCredential(fromAddress,fromPassword)
};
MailMessageemail=newMailMessage(fromAddress,"allen.yin.jun@gmail.com");
email.Subject="INLINEattachmentTEST";
email.IsBodyHtml=true;
stringattachmentPath="C:\\3.jpeg";
Attachmentinline=newAttachment(attachmentPath);
inline.ContentDisposition.Inline=true;
inline.ContentDisposition.DispositionType=DispositionTypeNames.Inline;
//inline.ContentId="1";
//inline.ContentType.MediaType="image/png";
inline.ContentType.Name=Path.GetFileName(attachmentPath);
email.Attachments.Add(inline);
email.Body="test";
smtp.Send(email);
email.Dispose();
//如果没有路径,用Stream
Attachmentletter=newAttachment(FileUploadLetter.FileContent,FileUploadLetter.PostedFile.ContentType);
letter.ContentDisposition.Inline=true;
letter.ContentDisposition.DispositionType=DispositionTypeNames.Inline;
//inline.ContentId="1";
letter.ContentType.MediaType=FileUploadLetter.PostedFile.ContentType;
letter.ContentType.Name=Path.GetFileName(FileUploadLetter.PostedFile.FileName);
letter.Name=Path.GetFileName(FileUploadLetter.PostedFile.FileName);
相关文章
- Tomcat多实例
- Java爬虫-URLConnection使用实例
- 腾讯ARC、华中科大联合提出QueryInst,开启基于Query的实例分割新思路
- MongoDB分片键的选择和案例实例详解
- MongoDB单表数据的导出和恢复实例讲解
- 利用Oracle数据库发送邮件的实例代码
- python中一些内置函数实例详解编程语言
- PHPMailer使用教程(PHPMailer发送邮件实例分析)
- jspsmart文件上传与邮件发送的实例
- Java自动解压文件实例代码
- c#代码自动修改解决方案下任意文件实例
- 使用PHP备份MySQL和网站发送到邮箱实例代码
- php使用curl发送json格式数据实例
- Javamail发送邮件的具体实例
- node.js使用nodemailer发送邮件实例
- python七种邮件内容发送方法实例
- thinkphp实现发送邮件密码找回功能实例
- Cocos2d-x中获取系统时间和随机数实例
- php实现的发送带附件邮件类实例
- PHP邮件发送类PHPMailer用法实例详解