c#

位置:IT落伍者 >> c# >> 浏览文章

.net SMTP发送Email实例(可带附件)


发布日期:2018年01月21日
 
.net SMTP发送Email实例(可带附件)
本文为大家详细介绍下net SMTP发送Email同时可带附件的具体实现思路及代码想实现的朋友可以参考下哈希望对大家有所帮助复制代码 代码如下:


public static void sendEmail(string toAddress string emailbody)
{
var fromAddress = ConfigurationManagerAppSettings["EmailAddress"];
string fromPassword = ConfigurationManagerAppSettings["EmailPassword"]ToString();
const string subject = "Job Recommendation";
var smtp = new SmtpClient
{
Host = ConfigurationManagerAppSettings["SmtpServer"]ToString()
Port = intParse(ConfigurationManagerAppSettings["SmtpPort"])
EnableSsl = true
DeliveryMethod = SmtpDeliveryMethodNetwork
UseDefaultCredentials = false
Credentials = new NetworkCredential(fromAddress fromPassword)
};
using (var message = new MailMessage(fromAddress toAddress subject HttpUtilityHtmlEncode(emailbody)))
{
smtpSend(message);
}
}
<add key="EmailAddress" value="**********@gmailcom"/>//Email Address
<add key="EmailPassword" value="*********"/> //Emial PWD
<add key="SmtpServer" value="smtpgmailcom"/>
<add key="SmtpPort" value=""/>
<带附件版本>
var fromAddress = "allenyinj@gmailcom";
string fromPassword = "yj";
const string subject = "CV";
var smtp = new SmtpClient
{
Host = "smtpgmailcom"
Port =
EnableSsl = true
DeliveryMethod = SmtpDeliveryMethodNetwork
UseDefaultCredentials = false
Credentials = new NetworkCredential(fromAddress fromPassword)
};
MailMessage email=new MailMessage(fromAddress "allenyinjun@gmailcom");
emailSubject = "INLINE attachment TEST";
emailIsBodyHtml = true;
string attachmentPath = "C:jpeg";
Attachment inline = new Attachment(attachmentPath);
inlineContentDispositionInline = true;
inlineContentDispositionDispositionType = DispositionTypeNamesInline;
//inlineContentId = "";
//inlineContentTypeMediaType = "image/png";
inlineContentTypeName = PathGetFileName(attachmentPath);
emailAttachmentsAdd(inline);
emailBody = "test";
smtpSend(email);
emailDispose();
//如果没有路径用Stream
Attachment letter = new Attachment(FileUploadLetterFileContent FileUploadLetterPostedFileContentType);
letterContentDispositionInline = true;
letterContentDispositionDispositionType = DispositionTypeNamesInline;
//inlineContentId = "";
letterContentTypeMediaType = FileUploadLetterPostedFileContentType;
letterContentTypeName = PathGetFileName(FileUploadLetterPostedFileFileName);
letterName = PathGetFileName(FileUploadLetterPostedFileFileName);

               

上一篇:.NET的动态编译与WS服务调用详解

下一篇:.Net中生成二维的表格的代码